Operating System - Linux
1826498 Members
1580 Online
109692 Solutions
New Discussion

Re: How i can edit various files at same time?

 
SOLVED
Go to solution
Francesco_13
Regular Advisor

How i can edit various files at same time?

Hi,
i have in my HP-UX 39 files(aprox. 18 mb ) that i'm do it to edit for changing the string: /*+ RULE */ for a space.
How i can do it at the same time with a loop?

Thenks.
best regards.
Francesco
9 REPLIES 9
Pete Randall
Outstanding Contributor
Solution

Re: How i can edit various files at same time?

Something like:

for FILE in `cat file_list`
do
sed 's|/*+ RULE */||g'`
done


Pete

Pete
Piergiacomo Perini
Trusted Contributor

Re: How i can edit various files at same time?

Hi Francesco and Pete,
you can use commands that Pete suggest but
better

for FILE in `cat file_list`
do
sed 's|/*+ RULE */||g'` $FILE
done

regards

Piergiacomo Perini
Trusted Contributor

Re: How i can edit various files at same time?

Hi again Francesco,

you can try this (last version ;-))

for FILE in `cat file_list`
do
sed "s/\/\*+ RULE \*\///" $FILE > $FILE
done

(please test before use it because
sed statement result is redirect
on original file)

regards
Pete Randall
Outstanding Contributor

Re: How i can edit various files at same time?

Thanks, Piergiacomo, I forgot the $FILE part!


Pete

Pete
Piergiacomo Perini
Trusted Contributor

Re: How i can edit various files at same time?

(no points, please)
No problem Pat, thank you for "begin the shell
script"!!!
Simon Hargrave
Honored Contributor

Re: How i can edit various files at same time?

Don't use sed with $FILE > $FILE you will blank all your files!

Either user $FILE > $FILE.tmp then mv $FILE.tmp to $FILE, or use ed: -

for FILE in *
do
ed $FILE <1,\$s/\/\*+ RULE \*\// /
w
q
EOF
done
Piergiacomo Perini
Trusted Contributor

Re: How i can edit various files at same time?

(obviusly no points)
thanx Simon , it's my fault (don't test shell
script).

regards
Rodney Hills
Honored Contributor

Re: How i can edit various files at same time?

perl can do it in 1 line-

perl -p -i -e 's{/\*\+ RULE \*/}{ }g' *

This will edit each file in-place (-i option).

HTH

-- Rod Hills
There be dragons...
Francesco_13
Regular Advisor

Re: How i can edit various files at same time?

Hi,
thanks to all !