Computing.Net > Forums > Unix > Sed: Add / to line matching pattern

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sed: Add / to line matching pattern

Reply to Message Icon

Name: weather91
Date: August 17, 2004 at 07:29:33 Pacific
OS: Mac OS X/Darwin
CPU/Ram: G5
Comment:

Hi!

As the subject says, I'd like to add a " /" to the end of a line containing a specific keyword. For instance:

in.txt:

a=1,b=2,c=3
d=4,keyword=5,f=6
g=7

out.txt:

a=1,b=2,c=3
d=4,keyword=5,f=6 /
g=7

where keyword is the keyword. I take it sed is the right tool, but I haven't seen an example quite like this online. Ideally, I'd like to insert this into a perl script, in case this changes the sed syntax or the same thing can be done in perl w/o sed. Thanks for your help.

--Kevin



Sponsored Link
Ads by Google

Response Number 1
Name: Wolfbone
Date: August 17, 2004 at 08:59:55 Pacific
Reply:

sed '/keyword/ s/$/ \//'

perl -e 'while (<>) {if (/keyword/) {s/$/ \//}; print}'



0
Reply to Message Icon

Related Posts

See More


Time calculation getting 9 char from a fil...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Sed: Add / to line matching pattern

how to match pattern on Bash? www.computing.net/answers/unix/how-to-match-pattern-on-bash/7228.html

Delete all lines containing pattern www.computing.net/answers/unix/delete-all-lines-containing-pattern/4499.html

sed question www.computing.net/answers/unix/sed-question/2914.html