0

Hey guys I'm stuck. I have been trying to write a sed or perl script to change the below. But each time I run the sed script or perl it completely zeros out the file.

I want to change this
/opt/dragon/bin/runit

to this
cd /opt/dragon/bin; /opt/dragon/bin/runit


#!/bin/bash
for fl in *.php; do
mv $fl $fl.old
sed 's/old/new/g' $fl.old > $fl
rm -f $fl.old
done

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by rch1231
0

Your sed line is saying to substitute the word new for the word old globally in the filename.old file and output to the original file name. You would need something like this:

sed s/\/opt\/dragon\/bin\/runit/cd\ \/opt\/dragon\/bin\ \;\ \/opt\/dragon\/bin\/runit/g

But this would do the same thing:

sed s/\/opt\/dragon\/bin\/runit/cd\ \/opt\/dragon\/bin\ \;\ \/\.\/runit/g

You have to use the backslash to tell sed to ignore the normal operation of the slash, space, semi-colon and period and make them part of the substitution. The second line changes to the directory then starting in the current directory run the program called runit.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.