sorry, just simple question:
how can i do this in bash>
foreach i( 1 2 3 )
sed 's/Hello/Howdy/g' test$i > test$i.new
mv test$i.new test$i
end
sorry, just simple question:
how can i do this in bash>
foreach i( 1 2 3 )
sed 's/Hello/Howdy/g' test$i > test$i.new
mv test$i.new test$i
end
for i in 1 2 3
do
sed 's/Hello/Howdy/g' test$i > test$i.new
mv test$i.new test$i
done
Some possibilities with bash:
for i in 1 2 3; do
# do your stuff here
done
or:
for (( i=1; i<=3; i++ )); do
# do your stuff here
done
or:
for i in `seq 3`; do
# do your stuff here
done
Regards
for i in 1 2 3; do
sed 's/Hello/Howdy/g' test$i > test$i.new
mv test$i.new test$i
done
If you have bash >=3.0 you can avoid the for loop and use brace expansion.
If you have a sed implementation that supports the i switch you can avoid the explicit temporary file:
$ print Hello >test{1..3}
$ head test*
==> test1 <==
Hello
==> test2 <==
Hello
==> test3 <==
Hello
$ sed -i 's/Hello/Howdy/' test[1-3]
$ head test*
==> test1 <==
Howdy
==> test2 <==
Howdy
==> test3 <==
Howdy
Or just use a more powerful tool:
perl -i -pe's/Hello/Howdy/' test[1-3]
thanx for the nice posts
Hi Franklin,
seq 3...this command does not seem to work on my system......!
You're right, the seq command is not available on most Unix systems, it's a part of the GNU Coreutils.
Regards