Operating System - HP-UX
1819915 Members
2275 Online
109607 Solutions
New Discussion юеВ

Re: global change with script

 
Ravinder Singh Gill
Regular Advisor

global change with script

there are approximately 50 scripts and are all in /home/sysscr and file names are *ftp*. We need to change uk\sunset to uk/sunset. How can I do this globally?
7 REPLIES 7
Vibhor Kumar Agarwal
Esteemed Contributor

Re: global change with script

Is this uk\sunset present in name of file or in the contents.

I assume its present in contents.

for filename in `find . -name "*ftp*"; do
sed -e 's/uk\\sunset/uk\/sunset/g' $filenaem > new_file;
mv new_file $filename;
done;
Vibhor Kumar Agarwal
Rick Garland
Honored Contributor

Re: global change with script

cat <$FILE> | sed 's/uk\/\sunset/uk\/sunset/g' > <$NEWFILE>
mv <$NEWFILE> <$FILE>


Can pipe through sed
Stuart Browne
Honored Contributor

Re: global change with script

And one with a perl twist:

for FILE in ftp*
do
perl -pi -e 's#uk\\sunset#uk/sunset#g' $FILE
done
One long-haired git at your service...
Ravinder Singh Gill
Regular Advisor

Re: global change with script

uk\sunset is in the contents of the files. So if I change direcory to home/sysscr & do

#for filename in `find . -name "*ftp*"; do
#sed -e 's/uk\\sunset/uk\/sunset/g' #$filenaem > new_file;
#mv new_file $filename;
#done;

it should work fine yea?
Muthukumar_5
Honored Contributor

Re: global change with script

Simply as,

# cd /home/sysscr
# perl -pi -e 's/uk\\sunset/uk\/sunset/' *ftp*

will do it.

hth.
Easy to suggest when don't know about the problem!
Vibhor Kumar Agarwal
Esteemed Contributor

Re: global change with script

Yup.

Now what do you prefer,
sed or perl.

I think perl one will be better.
But i don't know perl that's why i stick to sed. ;-)
Vibhor Kumar Agarwal
Ravinder Singh Gill
Regular Advisor

Re: global change with script

Thanks