's/^ *//' replaces any spaces at the beginning of the line with nothing, essentially stripping off leading whitespace.
^ matches the beginning of the line
the name space character matches at least one space
space then kleene star (*) matches any number (including 0) spaces
replace it with nothing.
's/^ +//' would be cleaner (match beginning of line and then 1 or more spaces) but I've been bitten by lack of + support in the dim past and so I naturally avoid it.
As for indentation, something like xmllint will do a better job, but for hackiness you could also just do something along the lines of:-
The sed separates tags onto a line by themselves and the perl does some rudimentary indentation.
Expect the above to blow up (especially for strings that contain embedded > or < characters). It's 5 minutes' work whilst distracted on a conference call.
's/^ *//' replaces any spaces at the beginning of the line with nothing, essentially stripping off leading whitespace.
^ matches the beginning of the line
the name space character matches at least one space
space then kleene star (*) matches any number (including 0) spaces
replace it with nothing.
's/^ +//' would be cleaner (match beginning of line and then 1 or more spaces) but I've been bitten by lack of + support in the dim past and so I naturally avoid it.
As for indentation, something like xmllint will do a better job, but for hackiness you could also just do something along the lines of:-
The sed separates tags onto a line by themselves and the perl does some rudimentary indentation.
Expect the above to blow up (especially for strings that contain embedded > or < characters). It's 5 minutes' work whilst distracted on a conference call.