LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author] [stats]
  From: Andrew Lord <andrewlord@internode.on.net>
  To  : <linuxsa@linuxsa.org.au>
  Date: Wed, 15 Jan 2003 00:02:07 +1030

Re: Search & Replace

On Sun, 12 Jan 2003 08:45 am, David Fitch wrote:
> On Sun, 2003-01-12 at 00:26, Andrew Lord wrote:
> > Nevertheless, for anyone else interested, the line is:
> > find . -print | egrep "*\.html" | xargs perl -pi -e 's/this/that/g'
>
> isn't that a more complicated way of doing:
> find . -type f -name "*.html" -exec perl -pi -e 's/this/that/g' {} \;
> (adding the "-print" makes it more portable outside of just linux)
> (and the "-type f" means only look at files not dirs)

Hi David,

I'd guessed at the role of -type f but thanks for the pointers on the 
functionality of -print.  

The line you suggested, " find . -type f -name "*.html" -exec perl -pi -e 
's/this/that/g' {} \;", also works a treat and recursively too.  Thanks for 
the alternative.  

It's wise to do this testing on some duplicate directory that means little.  
Fortunately I did.  Unfortunately, I included a leading 'g at the  beginnng 
of the /this/that.  The result was a little unexpected  (but perhaps not for 
anyone who has any insight into perl (?) . . . .  In a terminal the screen 
read "Ilegal division by zero at -e line 1, <> line 1.", for a over 200 lines 
(probably equivalent to the number of files under that directory).  A check 
of the files revealed that the entire content of all text files in all 
directories had been wiped, recursively.  Definitely /use/type/ with caution 
;)

> > 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.
>
> knock up a script like:
> read file/dir names
> if the name contains "this" then
>   newname = subsitute "this" for "that" in name
>   mv name to newname
> endif
>
> implementation and testing is left as an exercise...


Thanks for the structure.  I'll ponder on it.  

Cheers,

Andrew Lord
>
> Dave.


-- 
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