dmshawkat
asked on
Shell Script for addition ann run against multiple files
I have the following Shell Script where it replacing old string/lines with new lines in a
file (actually it is a makefile)
The script works halfway though, , since when it encounters space or tab it does not replace old strings/lines
My question is using this K-Shell Script
1. how to take care space or tab fro the replacement ?
2. I want to add a new line (LINK = cc -G -mt -o) in all files ?
3. I am running the script against one file
sed -f test.sed input.txt > output.txt
Instead how can I run the script against all 100 files ( they are all same type makefile) ?
Following is the script I am using
!/bin/ksh
#
#The script substitute old lines with new lines in *.mak file
s/-D_HPUX_SOURCE -DFND_HPUX/-D__sun -DFND_SUN/
s/-Dfnd_hp -c -Aa $(DEBUG) +O2 +DS897/-Dfnd_sun \$(DEBUG) -c -Xa -O -xcg92 -xcode=pic32/
s/LINKFLAGS = -Wl,-B,immediate,+s,-q/#LI NKFLAGS = -Wl,-B,immediate,+s,-q/
LINK = cc -G -mt -o/
#Run Syntax
#sed -f test.sed input.txt > output.txt
Thanks :)
file (actually it is a makefile)
The script works halfway though, , since when it encounters space or tab it does not replace old strings/lines
My question is using this K-Shell Script
1. how to take care space or tab fro the replacement ?
2. I want to add a new line (LINK = cc -G -mt -o) in all files ?
3. I am running the script against one file
sed -f test.sed input.txt > output.txt
Instead how can I run the script against all 100 files ( they are all same type makefile) ?
Following is the script I am using
!/bin/ksh
#
#The script substitute old lines with new lines in *.mak file
s/-D_HPUX_SOURCE -DFND_HPUX/-D__sun -DFND_SUN/
s/-Dfnd_hp -c -Aa $(DEBUG) +O2 +DS897/-Dfnd_sun \$(DEBUG) -c -Xa -O -xcg92 -xcode=pic32/
s/LINKFLAGS = -Wl,-B,immediate,+s,-q/#LI
LINK = cc -G -mt -o/
#Run Syntax
#sed -f test.sed input.txt > output.txt
Thanks :)
ls -1 input* | while read infile # generate flist of filenames (could use find instead of ls)
do # loop
outfile=`echo $infile | sed s!input!output!` # create output filename
sed -f test.sed $infile > $outfile # edit contents
done # end loop
OR if you want to overwrite original:
ls -1 input* | while read infile # generate flist of filenames (could use find instead of ls)
do # loop
sed -f test.sed $infile > /tmp/tempf$$ # edit contents
cp /tmp/tempf$$ $infile # overwrite original
done # end loop
Cheers
JJ
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello Dear
I am getting following erra when runnining the replacement
sed: command garbled: s/LINKFLAGS = -G -mt -o/LINKFLAGS = -G -mt/
Any hlep would be greatly appraciated
Thanks
Shawkat
did you test my suggestion?
still believe in my suggestion ..
Hm.. I wondered a bit here :)
I will check it again but something is not quite ok for me... Just my gut probably but let me rethink
I will check it again but something is not quite ok for me... Just my gut probably but let me rethink
> .. is not quite ok for me ..
ok, may be the + needs to be escaped if you're using Gnu sed
but I assumed standard AT&T sed 'cause we're in Unix TA :-)
ok, may be the + needs to be escaped if you're using Gnu sed
but I assumed standard AT&T sed 'cause we're in Unix TA :-)
:)Yeah... :)
Time to change the recommendation... :)
Time to change the recommendation... :)
In the second line you need to escape the first $, too. $(DEBUG)
Good Luck!
Kent