sed

Multiline Input

The following will concatenate continuation lines in an LDAP dump in ldif format to a “relaxed” ldif format with arbitrary long lines:

sed -n '1h;1!H;${g;s/\n //g;p;}' /tmp/ldap_schema.ldif > /tmp/ldap_schema_longline.ldif

Meaning of the tokens:

1h copy first line into hold space
1!H append every line but the first one to hold space
${ execute on last line
g copy hold space to pattern space
s/\n //g delete newline + space
p print pattern space

Thanks to Austin Matzko for giving a working example.

Back to top
docs/tips_n_tricks/sed.html.txt · Last modified: 2011/02/22 17:16 by peter