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!

append text on second word

Status
Not open for further replies.

dbase77

Technical User
Apr 23, 2002
591
IE
Hi,

I have a file like this:

.
.
.
set trimspool on
.
.
spool filename
.
.
.
spool off
exit

What I want to do is to append a full path directory to the filename only. So it should read like this:

.
.
.
set trimspool on
.
.
spool /home/john/filename
.
.
.
spool off
exit

Is ther any way I can do this in awk or sed? I tried to grep for "spool" but the result I got back was too many lines since the file itself contains more than 1 spool word. Sometimes it contains only 2 spool words like "spool filename and spool off".

Thank you in advance.

regards,
dbase77
 
Something like this ?
awk '
$1=="spool" && $2!="off"{print "spool /home/john/"$2;next}
{print}
' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

sweet. It worked the way I want it. You the best. Thank you very much.

Why it didnt pick up word trimspool? coz I tried
awk '/spool/ {print}' and it picked up all the occurence of spool word.

regards,
dbase77
 
man awk

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