Operating System - HP-UX
1829735 Members
2129 Online
109992 Solutions
New Discussion

Change on multiple files...

 
SOLVED
Go to solution
Vittorio_3
Advisor

Change on multiple files...

Hi,
Is there a way to make global change on a multiple files using any command.
I know that I can feed sed only with < fname,
can I specify multiple files?
Let say I need to change 'white' for 'black' in files ff1,ff2,ff3,ff4....f99.

Thanks
Dai
8 REPLIES 8
baiju_3
Esteemed Contributor
Solution

Re: Change on multiple files...

Try this .

ls -1 ff* |while read file ;do

sed 's/white/black/g' >$file.new

done


thx,
bl.
Good things Just Got better (Plz,not stolen from advertisement -:) )
Pete Randall
Outstanding Contributor

Re: Change on multiple files...

for FILE in "ff1 ff2 ff3 ff4 f99"
do
sed
done


Pete

Pete
Jean-Luc Oudart
Honored Contributor

Re: Change on multiple files...

Hi

I believe you will have to run a loop
such as
for filename in $(ls ff*)
do
...
done

Regards
Jean-Luc
fiat lux
Marvin Strong
Honored Contributor

Re: Change on multiple files...




perl -pi -e 's/white/black/g' $file1 $file2 ...



Marvin Strong
Honored Contributor

Re: Change on multiple files...

Also just to note if you just want to replace the first occurence on a line you should leave the g off the end of the s/white/black/g so it would look like s/white/black

James R. Ferguson
Acclaimed Contributor

Re: Change on multiple files...

Hi:

You could use perl and edit the files inpalce:

# perl -i.old -pe 's/hello/bye/' file1 file2 file3

In the above example, a backup copy of the original files is preseved as "*.old".

Regards!

...JRF...
Marvin Strong
Honored Contributor

Re: Change on multiple files...

one more idea if your list of files is large.
you can create a file with all the files in it.

perl -pi -e 's/white/black/' `cat list`


Kirby A. Joss
Valued Contributor

Re: Change on multiple files...

If you want a little more control, or the chance to review changes before saving each file in place, reasonably current versions (I've got 5.3 from 6/2002) of the full-screen (motif) editor "nedit" ( http://www.nedit.org/ available for 11i at the hpux porting centre, http://hpux.cs.utah.edu/ and mirrors) is a Godsend. The "Replace" option is under the "Search" menu.