Operating System - HP-UX
1828451 Members
3650 Online
109978 Solutions
New Discussion

Re: Scripting help needed!

 
SOLVED
Go to solution
Andrew Beal
Frequent Advisor

Scripting help needed!

Hi,

I have hundreds of files that are exactly the same across multiple file systems. I need to add one word "receipt" one space after the occourance of the word "suptran" in each of these files.

I had an idea that sed might be able to do it for me, but I have only seen examples of this replacing text in a file.

I would appreciate it if someone could show me how to do this.

Thanks in advance,

Andrew
3 REPLIES 3
William Wong_2
Trusted Contributor
Solution

Re: Scripting help needed!

sed will work just fine for what you are trying to do. There is no reason when you do a search and replace that you can append text for the keyword. So you would do the following:

sed -e "s/receipt/receipt suptrain/g"
Fragon
Trusted Contributor

Re: Scripting help needed!

Hi,Andrew
Just replace the word "suptran" with the string "suptran receipt", a demo script:
#!/usr/bin/sh
for filenm in /somedir
do
sed 's/suptran/suptran receipt/g' $filenm >$$.new
mv $$.new $filenm
done


-ux
Andrew Beal
Frequent Advisor

Re: Scripting help needed!

Thankyou all for your help.

Both your suggestions worked perfectly, and I have created the script that I needed.

Cheers ;)

Andrew