[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] replacing strings in multiple files.



* Barrie Bremner (baz [at] barriebremner.com) wrote:
> Richard Lowe writes:
>  > * Richard Lowe (richlowe [at] btinternet.com) wrote:
> 
>  > > * Barrie Bremner (baz [at] barriebremner.com) wrote:
> 
>  > > > Is there an easy way (script preferably) that can grep out my old
>  > > > address string and replace it with the new one?
> 
>  > > very very slightly tested (-i will make backups, but i suggest you so it
>  > > anway).
>  > > 
>  > > for i in *.html; do perl -wpi.bak -e 's/old email/new email/g' $i; done
>  > > 
>  > > 
>  > 
>  > I dont know how that loop crept in there, I blame the fact its late.
>  > 
>  > perl -wpi.bak -e 's/old email/new email/g' *
> 
> for i in *.html;
> do perl -wpi.bak -e 's/oldusr\@olddomain/newusr\ [at] newdomain/g' $i;
> done
> 
> Seems to do the trick. Backups an' all!
> 
> I need to learn perl.
> It was clever even enough to tell me to escape the  [at] 's  - I like that.
> 
> I know nothing of the syntax - but you mention a while loop - the $i I
> assume.
> 
> I am right in saying * is for all cases whereas $i would be once for
> each html file?
> 

yes.

the first way used a loop in bash for each file matching *.html.
The second way is better.

perl -wpi.bak -e 's/foo/bar/g' *.html

does exactly the same thing and is far easier to type :-).
(i just used * because i realised there may files other than html files)


I'm not sure exactly why i thought there for loop was needed.
I've spent all evening trying to find a bug in efsd and I think its
fried my brain :-)
 

--
|*-------------------=[ Richard Lowe ]=------------------*|
| richlowe [at] btinternet.com                   UIN: 74724348 |           
|*-------------------------------------------------------*|
| Europe has the Kilogram and the Meter.                  |
| America has the Pound and the Inch.                     |
| Childrens TV has the Elephant and the Double Decker Bus |
|*-------------------------------------------------------*|
---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word 
 "unsubscribe" in the body of the message. 

  GNU the choice of a complete generation.