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 Sed

Status
Not open for further replies.

g2345c

Technical User
Jun 23, 2004
22
US
I want to search a text file for any line that has "*.info" or "*.err", If i found it I insert the string ";none" before the 'tab'.

I sucessfully do either "*.info" or "*.err" but dont know how to do both on the same line. Please help. How do I put a 'or' statement in the below line to also change the *.err line as well

sed -e '/\*.info/b' -e'/\*info/s/ /;none /' file.txt > newfile.txt

Please help
Thanks
 
any line that has "*.info" or "*.err", If i found it I insert the string ";none" before the 'tab'
sed '/\*.info/bl1^J/\*.err/!b^J:l1^Js/^I/;none^I/' file.txt > newfile.txt
^J is a LF char (Ctrl-V Ctrl-J in vi mode)
^I is a Tab char.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi PHV,
I try it and it say "sed: -e expression #1, char 40: Extra characters after command"

here is the file.txt
*.info;mail.none;news.none;authpriv.none;cron.none /var/log/messages
*.err;mail.none;news.none;authpriv.none;cron.none /var/log/message


Please help
Thanks

 
And this ?
sed -e '/\*.info/bl1' -e '/\*.err/!b' -e ':l1' -e 's/Tab/;noneTab/' file.txt > newfile.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV, it works perfectly.
For Education purposes. If I wish to add *.warning and *.notice to the list How do I do it?

Thanks
 
sed -e '/\*.info/bl1' -e '/\*.warning/bl1' -e '/\*.notice/bl1' -e '/\*.err/!b' -e ':l1' -e 's/Tab/;noneTab/' file.txt > newfile.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks a lot it work perfectly.
I want to enhance this script so that if string ";none" not presented before the "Tab" then add it. If it's already there then dont add it. How do I check in this statement?

sed -e '/\*.info/bl1' -e '/\*.warning/bl1' -e '/\*.notice/bl1' -e '/\*.err/!b' -e ':l1' -e 's/Tab/;noneTab/' file.txt > newfile.txt

Thanks
 
sed -e '/;noneTab/b' -e '/\*.info/bl1' -e '/\*.warning/bl1' -e '/\*.notice/bl1' -e '/\*.err/!b' -e ':l1' -e 's/Tab/;noneTab/' file.txt > newfile.txt

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