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

Sed multiple input files and output multiple files with one command 1

Status
Not open for further replies.

keusch

Technical User
Jun 17, 2001
41
US
Simple question:
I want to do a simple sed edit on multiple files with one script. This can be done with the * command for input file names.
sed -e 's/STOP/ /g' *.lst
How do I output to a string of file names? I would like to output old file name with new added to the filename. ie input file name 1.lst > output file to be new1.lst
Another option would be to replace data in existing file - that would work as well.
I read that runsed could be used but I don't seem to have that application.
Any suggestions???
In the past I've just made a directory of all the files and created a file with the sed script on each line opening each file and directing it to the new file.
It's got to be easier.
Thank you.
 
something like that:
#!/bin/ksh

for i in *.lst
do
sed -e 's/STOP/START/g' ${i} > ${i%.*}.new
done;


#----------- or something like that does it 'inplace'
#!/bin/ksh

for i in *.lst
do
ex - ${i} <<EOF
%s/STOP/START/g
wq!
EOF
done;
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
ooops - misread the 'new' file name convention - change 'START' to whatever you'd like:
#!/bin/ksh

for i in *.lst
do
sed -e 's/STOP/START/g' ${i} > new${i}
done;
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
vgersh99
Thanks for both your replys. Very helpful indeed.
On the replace example, I hadn't thought of ex - I'd never used it before - looks alot like vi.
In anycase, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top