Solved

A script for modifying same lines for multiple same type files

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

Accepted Solution

by:
tel2 earned 250 total points
Comment Utility
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
Comment Utility



`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 11

Expert Comment

by:tel2
Comment Utility
Hi dmshawkat,

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

Thanks.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now