Shell Script for addition ann run against multiple files

Posted on 2006-06-20
Last Modified: 2008-03-10
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

#The script substitute old lines with new lines in *.mak file

s/-Dfnd_hp -c -Aa $(DEBUG) +O2 +DS897/-Dfnd_sun \$(DEBUG) -c -Xa -O -xcg92 -xcode=pic32/
s/LINKFLAGS     =  -Wl,-B,immediate,+s,-q/#LINKFLAGS     =  -Wl,-B,immediate,+s,-q/
LINK = cc -G -mt -o/

#Run Syntax
#sed -f test.sed input.txt > output.txt

Thanks :)
Question by:dmshawkat
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 45

Expert Comment

by:Kent Olsen
ID: 16947755
Hi dmshawkat,

In the second line you need to escape the first $, too.   $(DEBUG)

Good Luck!

Expert Comment

ID: 16949402

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

LVL 51

Accepted Solution

ahoffmann earned 125 total points
ID: 16952149
s/-Dfnd_hp -c -Aa $(DEBUG) +O2 +DS897/-Dfnd_sun $(DEBUG) -c -Xa -O -xcg92 -xcode=pic32/
s/LINK = cc -G -mt -o/your replacement here/

write above 4 line in file called test.sed, then
#Run Syntax
#sed -f test.sed input.txt > output.txt
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.


Author Comment

ID: 16980516

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

LVL 51

Expert Comment

ID: 16981520
did you test my suggestion?
LVL 51

Expert Comment

ID: 17555089
still believe in my suggestion ..
LVL 20

Expert Comment

ID: 17555892
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
LVL 51

Expert Comment

ID: 17556056
> .. 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 :-)
LVL 20

Expert Comment

ID: 17556134
:)Yeah... :)

Time to change the recommendation... :)

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question