Solved

A script for modifying same lines for multiple same type files

Posted on 2006-06-19
3
293 Views
Last Modified: 2010-04-21
Hello

I am trying to write a K-Shell script that will modify certain lines ( same line across files)
in multiple files.

Example:  A line exist as
HPUXCFLAGS      = -I. $(INC) -I$(FNDROOT)/include \
                  -D_HPUX_SOURCE -DFND_HPUX \
                  -Dfnd_hp $(DEBUG) -c +z -Aa -Ae +O2 +DS897 -I$(ORACLE_HOME) precomp/public

I have to replace the above lines by

HPUXCFLAGS      = -I. $(INC) -I$(FNDROOT)/include \
                  -D__sun -DFND_SUN \
                  -Dfnd_sun $(DEBUG) -c -Xa -O -xcg92 -xcode=pic32      -I$(ORACLE_HOME)/precomp/public

Also a line exist as

 LINK = ld -b -o
 
The above line need to be replaced by

LINK = cc -G -mt -o




0
Comment
Question by:dmshawkat
[X]
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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
tel2 earned 250 total points
ID: 16938496
Hi dmshawkat,

Will you supply a list of filenames as arguments to the script, or do you want it run on all the files in a directory, or what?

Are you willing to have a ksh and Perl solution (do you have Perl on your system)?
0
 
LVL 6

Expert Comment

by:JJSmith
ID: 16938864



`command to list files ie ls -1` | while read filen
do
  cat $filen       | sed s!-D_HPUX_SOURCE -DFND_HPUX!-D__sun -DFND_SUN!g > /tmp/tp1
  cat /tmp/tp1  | sed s!-Dfnd_hp \$\(DEBUG\) -c +z -Aa -Ae +O2 +DS897!-Dfnd_sun $(DEBUG) -c -Xa -O -xcg92 -xcode=pic32!g > /tmp/tp2
  cat /tmp/tp2  | sed s!LINK = ld -b -o!LINK = cc -G -mt -o!g > /tmp/tp1
 
  ......... I've escaped \ the $ , ( and ) - but you might have to escape - and + ; try it
  ......... repeat sed s!some pattern!replacement pattern!g .... using tp1 and tp2 untill you've finished all substitutions - then

  cp /tmp/tp1 $filen  OR   cp /tmp/tp2 $filen  # whichever temporary file you finished last with.
done
rm -f /tmp/tp1 /tmp/tp2


Cheers
JJ
0
 
LVL 12

Expert Comment

by:tel2
ID: 16947521
Hi dmshawkat,

Looks as if these points went to me instead of JJ.
Please ask the moderator to correct that.

Thanks.
0

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

729 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