Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using SED in unix shell programming

Status
Not open for further replies.

Maplologue

Programmer
Mar 26, 2003
1
FR
Hi every body,
I have a problem with the UNIX sed command. I have a file named Script that contains those instructions.

sed s/old1/new1/g SourceFile >Result
sed s/old2/new2/g SourceFile >Result
sed s/old3/new3/g SourceFile >Result

And when I execute this file, only the last command is taken into account not the first 2.

Does anyone know what the matter is?
 
sed 's/old1/new1/g;s/old2/new2/g;s/old3/new3/g' SourceFile >Result vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Your appear to changing the same data and sending it to the same file

do

sed s/old1/new1/g SourceFile > 1
sed s/old2/new2/g 1 > 2
sed s/old3/new3/g 2 > Result



--
| Mike Nixon
| Unix Admin
| ----------------------------
 
iribach,
one would assume that the 'new' and the 'old' patterns are just the mnemonic place-holders. vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
vgersh99,
my version is just a shorthand of yours.
in your version are 'old' and 'new' mnemonic ...

Maplologue, it will work IF (for unix beginners only)

sed 's/old1/new1/g' SourceFile >Result
[ -s Result ] && mv Result SourceFile || exit
sed 's/old2/new2/g' SourceFile >Result
[ -s Result ] && mv Result SourceFile || exit
sed 's/old3/new3/g' SourceFile >Result
[ -s Result ] && mv Result SourceFile || exit





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top