LinuxSA Mailing list archives
Index:
[thread]
[date]
[subject]
[author]
[stats]
From: Andrew Lord <andrewlord@internode.on.net>
To : <linuxsa@linuxsa.org.au>
Date: Sun, 12 Jan 2003 00:26:27 +1030
Re: Search & Replace
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