Solved

A script for modifying same lines for multiple same type files

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now