[ale] Sed help with append

Hunter Eidson Hunter.Eidson at gpc.edu
Tue Mar 23 15:28:49 EDT 2010


[I think my original reply got canceled, so if this is a dupe, my apologies]

This may not be what you're looking for (it isn't pretty),  and it may not even be portable outside of my test box, but this seems to get the result you are looking for:

$ sed 's/^\(ServerName \(.*\)\)$/\1\nServerAlias www.\2/' test.txt   
<VirtualHost 12.34.567.89>
ServerAdmin webmaster at domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /does/not/matter
</VirtualHost>

	--Hunter

--
Hunter Eidson
System Administrator
Enterprise Support / OIT
Georgia Perimeter College
hunter.eidson at gpc.edu
678-891-2502


-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of Jim Seymour
Sent: Tuesday, March 23, 2010 11:35 AM
To: ALE
Subject: [ale] Sed help with append

Hi,

I am trying to expand my capabilities with sed use. What I am trying
to do is modify an apache virt file as follows. The file containing
the lines to modify is named test.

<VirtualHost 12.34.567.89>
ServerAdmin webmaster at domain.com
ServerName domain.com
DocumentRoot /does/not/matter
</VirtualHost>

It needs a ServerAlias appended after ServerName as www.domain.com

What am I missing to get the pattern match in the append?

jim at swift ~ $ sed '/ServerName \(.*\)/ a\ServerAlias www.\1' test
<VirtualHost 12.34.567.89>
ServerAdmin webmaster at domain.com
ServerName domain.com
ServerAlias www.1
DocumentRoot /does/not/matter
</VirtualHost>

Have not been able to locate anything by googling about combining an
append with a remembered pattern. I even tried combining it into an
append the line and then do a substitute on the appended line to no
avail. I have a feeling there is probably something simple I have
missed somewhere.

Thanks,
-- 
Jim Seymour
_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo



More information about the Ale mailing list