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 wOOdy-Soft 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 a simple awk statement

Status
Not open for further replies.

g2345c

Technical User
Jun 23, 2004
22
US
hi, I want to add a line to file new.log if /var/log/new.log is not presented in the file.
But it add:
$A_STRING /var/log/new.log
instaed of
local0.debug /var/log/new.log


#!/bin/sh
A_STRING=local0.debug

awk '/\/var\/log\/new.log/{++n}{print}END{if(!n)print "\n$A_STRING /var/log/new.log"}' syslog.conf > tmp.conf

thanks
 
Have you tried this ?
awk '/\/var\/log\/new.log/{++n}{print}END{if(!n)print "\n'$A_STRING' /var/log/new.log"}' syslog.conf > tmp.conf
Or this ?
fgrep -q "$A_STRING" syslog.conf || echo "\n$A_STRING /var/log/new.log" >> syslog.conf

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