Operating System - HP-UX
1829115 Members
13443 Online
109986 Solutions
New Discussion

sed and a script file (-f script_file)

 
SOLVED
Go to solution
Stephen Badgett
Regular Advisor

sed and a script file (-f script_file)

I would like to use sed and "-f script_file" or " -e script"

I am currently using sed to do changes and like using it but since I have a lot of changes that are needed I thought of using
a -f or the -e option.

small sample:

sed "s/Cap: /CAPACITY /" old.sch > new.sch
sed "s/Trial /TRIAL /" new.sch > new1.sch


Steve
Not as is, is now
2 REPLIES 2
Sridhar Bhaskarla
Honored Contributor
Solution

Re: sed and a script file (-f script_file)

Hi Steve,

I would put the sed commands in a file say infile like this

s/Cap:/CAPACITY/
s/Trial/TRIAL/

and run sed as

sed -f infile old.sch > new.sch

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: sed and a script file (-f script_file)

Sounds like a plan. Simply combine each of your instructions in a single file and use the -f option to identify your script file. This will be much more efficient than applying one rule at a time. Be aware that the commands are processed sequentially so that, for example, if you have an instruction
that substitues "cat" for "dog" and a subsequent instruction that substitutes "cow" for "cat" then all of your dogs as well as your cats will become cows whether that was your intention or not.
If it ain't broke, I can fix that.