shell script question
Randal Schwartz
merlyn at iwarp.intel.com
Sun Mar 4 03:41:15 AEST 1990
In article <652 at sagpd1.UUCP>, jharkins at sagpd1 (Jim Harkins) writes:
| I have a list of files in which I want to change the word 'foo' to the filename.
| What I tried to do was
|
| foreach i (list of files)
| sed 's/foo/$i/' < $i > tmp
| mv tmp $i
| end
|
| But what this does is replace 'foo' with '$i', not the filename. Can anybody
| help? I'm running 4.3 BSD UN*X. Thanks.
Single quotes prevent the CSH from interpreting '$i'. Your solution
using csh/sed is:
foreach i (list of files)
sed "s/foo/$i/" <$i >tmp
mv tmp $i
end
My one-liner solution using Perl is:
perl -pi -e 's/foo/$ARGV/;' list of files
Just another Perl hacker,
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.questions
mailing list