[K12OSN] Help with sed script!

Timothy Legge timlegge at gmail.com
Fri Aug 10 02:22:31 UTC 2007

On 8/9/07, Les Mikesell <les at futuresource.com> wrote:

> Sed does have a way to do things like that with hold and get operations
> across multiple lines, but the syntax is fairly insane compared to perl.
>   And sed is another program where you need to use info instead of man
> for the real documentation - or google for sed and holding space for
> some examples.

Because it is possible:

sed -n '/DC=LO/!{p;b};s/ *$//;h;n;s/^ *//;x;G;s/\n//p' filename

;-) save the following to a file and execute with the filename to
process as the parameter.

sed -n '
# print line and branch to end only for non matching lines
# remove trailing spaces
s/ *$//
# store the current line
# read next line destroying current line
# remove reading spaces
s/^ *//
# swap the current line and stored line
# append the new stored line to the current line
# remove embedded new line
' $2

note that I had to use sed's -n and manually print because otherwise
it seemed to print both  the original and new line (there is probably
a simple solution).


More information about the K12OSN mailing list