[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [K12OSN] Help with sed script!



On 8/9/07, Les Mikesell <les 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:

Join LOCAL:
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
/DC=LO/!{p;b}
# remove trailing spaces
s/ *$//
# store the current line
h
# read next line destroying current line
n
# remove reading spaces
s/^ *//
# swap the current line and stored line
x
# append the new stored line to the current line
G
# remove embedded new line
s/\n//p
' $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).

tim


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]