LinuxSA Mailing list archives
Index:
[thread]
[date]
[subject]
[author]
[stats]
From: Andrew Lord <andrewlord@internode.on.net>
To : <linuxsa@linuxsa.org.au>
Date: Tue, 14 Jan 2003 23:32:55 +1030
Re: Search & Replace
On Sun, 12 Jan 2003 10:40 am, you wrote:
> I used a command in a spamassassin script I wrote.
>
> *Goes to download it*
>
> The command:
>
> perl -i -wpe 's/type", "pop3"/type","movemail"/g' prefs.js
>
> Scans the prefs.js file for ----> type", "pop3"
>
> and replaces any incident of it with ------->
> type","movemail"
Thanks James,
Yes, it certainly works as well as the one I found, for the contents of files
in the current directory, but unfortunately doesn't work recursively and
doesn't change the file (or directory) name either. Thanks for the thought.
Cheers,
Andrew Lord
>
> This is the only Perl that I know to refer to now and then, and I have
> no idea what the -i or -wpe means, other than, it works.
>
> James Leone
>
> andrewlord@internode.on.net wrote:
> >On Fri, 10 Jan 2003 10:34 pm, Ant wrote:
> >
> >Thanks for your reply Ant,
> >
> >>How about (untested):?
> >>
> >>find . --exec perl -pi 's/targetText/replacementText/g' {} \;
> >
> >Well I tried this as you suggested and the response result was:
> >
> >find: invalid predicate `-pi'
> >
> >Upon trying this, I realised that I had left an '-e' out of the line I
> > posted to the group. Unforgivable and I hope it's wasted no-ones time as
> > a result. Appologies if it has.
> >
> >The correct line shold have read
> > bash $ perl -pi -e 's/targetText/replacementText/g' *
> >
> >So I've gone and tried a few different options based on your suggestions
> > and the results follow:
> >$ find . --exec perl -pi -e 's/targetText/replacementText/g' {}\;
> > find: invalid predictate `--exec'
> >$ find . perl -pi -e 's/targetText/replacementText/g' {}\;
> > find: invalid predictate `-pi'
> >$ find . perl -e 's/targetText/replacementText/g' {}\;
> > find: invalid predictate `-e'
> >$ find . perl -e 's/targetText/replacementText/g' {}\;
> > ./directoryname
> > ./directoryname/filename
> > ./directoryname/filename2 (etc)
> > ./directoryname/subdirectoryname (etc)
> > find: s/targetText/replacementText/g: No such file or directory
> > find: {};: No such file or directory
> >
> >So basically the final command succeeds in recursively listing the entire
> >contents of that directory, but no changes.
> >
> >I've now resorted to a longer trawl of the web and found the following.
> > It works well for replacing 'this' with 'that', recursively, in all .html
> > files (or in any file at all using * instead) but unfortunately fails to
> > change file names and directory names.
> >
> >Nevertheless, for anyone else interested, the line is:
> >find . -print | egrep "*\.html" | xargs perl -pi -e 's/this/that/g'
> >
> >Works down through two subdirectories and I suppose it would work further
> > too (not tested though).
> >
> >I'd welcome further suggestions on how this could be enhanced to replace
> >'this' with 'that' in file and directory names, or even any ideas on a
> >separate line of code that will do this task.
> >
> >Cheers,
> >
> >Andrew Lord
--
LinuxSA WWW: http://www.linuxsa.org.au/ IRC: #linuxsa on irc.openprojects.net
To unsubscribe from the LinuxSA list:
mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
Index:
[thread]
[date]
[subject]
[author]
[stats]
Return to the LinuxSA Mailing List Information Page