Xref: utzoo comp.unix.questions:20364 comp.lang.perl:531 Path: utzoo!mnetor!tmsoft!torsqnt!jarvis.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!snorkelwacker!tut.cis.ohio-state.edu!ucbvax!decwrl!orc!mipos3!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: shell script question Message-ID: <1990Mar3.174115.15049@iwarp.intel.com> Date: 3 Mar 90 17:41:15 GMT References: <652@sagpd1.UUCP> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 30 In-Reply-To: jharkins@sagpd1.UUCP (Jim Harkins) In article <652@sagpd1.UUCP>, jharkins@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@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/