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!

Add char from CAT output

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have the following file :

toto DODO /data/jhksdql
tutu DODO /data/hjdhqsjkd
titi DADA /data/nhjfsk
tata DUDU /data/gafdgz

1) I want to extract the lines with DODO only
so I do "cat file | grep DODO > /tmp/filetmp"

2) Now I want to add "ro" at the end of each line of filetmp to get

toto DODO /data/jhksdql ro
tutu DODO /data/hjdhqsjkd ro

Can I do this in one statement with the previous cat command?

Thanks!

 
Try this :
[tt]
sed -e '/DODO/!d;s/$/ ro/' file

/DODO/!d <- delete all lines not containing DODO
s/$/ ro/ <- add &quot; ro&quot; at end of line
[/tt]

Jean Pierre.
 
The awk way:
Code:
awk '$2==&quot;DODO&quot;{print $0&quot; ro&quot;}' infile >/tmp/filetmp

Hope This Help
PH.
 
Thanks guys! Jean Pierre's suggestion did not work (sed -e '/DODO/!d part) so I used cat | grep instead. s/$/ ro/ worked fine!
 
On my AIX box the sed command works fine.

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top