Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with awk or sed

Status
Not open for further replies.

g2345c

Technical User
Jun 23, 2004
22
US
Hi,
Please help me to write an awk or sed statement that do:

1. if see any line that started with "local0." (local0 follow by a dot) replace the entire line with "local0.debug /var/test"
2. If I dont see any line that started with "local0." append "local0.debug /var/test" to the file

here is that I have but It only append(2) but not replace(1)

awk '/^local0./{++n}{print}END{if(!n)print "\nlocal0.debug \/var\/test"}' syslog.conf > syslog.conf.11


Please help
 
awk '
/^local0\./{++n;print "local0.debug /var/test";next}
{print}
END{if(!n)print "\nlocal0.debug /var/test"}
' syslog.conf > syslog.conf.11

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top