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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed substitution help

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
CA
How do I search on a particular pattern, and if a line contains that pattern, add a comment in front of the line - leaving the rest of the line unchanged.

Input file: (I want to only comment out the line that contains 'WOW1' - not WOW11')

abcd WOW1 cdef
abcd WOW11 cdef

Output file:

#abcd WOW1 cdef
abcd WOW11 cdef
 
Does
Code:
sed "/WOW1 /s/^/#/" inputfile
do what you want? CaKiwi
 
Great! Both worked. I also discovered another solution:

sed "s/^.*WOW1 /#&/" input
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top