Appending text in a file
Gerald Combs
gerald at ethereal.com
Fri Apr 25 21:51:50 CDT 2003
On Fri, 25 Apr 2003, Jonathan Hutchins wrote:
> I have an LDIF file with a bit over 300 entries. I need to append some text
> (",ou=contacts,dc=tarcanfel,dc=net") to each line that begins with "dn:".
>
> Surely there's an easy way to script this.
>
> Using sed, I can append text, but only as the next line.
awk '/^dn:/ {printf "%s,ou=contacts,dc=tarcanfel,dc=netn", $0} ! /^dn:/ {print}' < [data
file]
The first expression ("/^dn:/") appends the text. The second expression
("! /^dn:/") prints the line unchanged for anything that doesn't match
the first expression.
More information about the Kclug
mailing list