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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.