Solved

A script for modifying same lines for multiple same type files

Posted on 2006-06-19
3
286 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

696 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