Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A script for modifying same lines for multiple same type files

Posted on 2006-06-19
3
Medium Priority
?
302 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 750 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

Technology Partners: 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

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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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 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…
Suggested Courses

636 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