PDA

View Full Version : A simple place/replace script


MrD
02-15-2003, 08:35 AM
Hi All,

I'm trying a simple place and replace script to edit over a 100 txt files.
It should be something like
find between "<br>.....</br>" replace with "|"
or what ever.

I'm having problems with :
1. Reading all file in the directory - tried using glob ("$url") but deosn't seem to work well
2. Find in between ??

thanks in advance
Danny

ian17
02-20-2003, 03:41 PM
Danny,
Your question doesn't make any sense to me. <BR> is a line break tag in HTML. </BR> is forbidden, it's not a real tag.

Do you mean you want to insert "|" pipe characters in between paragraph tags? changing from <P>abc</P> <P>def</P> to abc | def , for instance? Or change from <P>abc</P> to | ?? I can't give you any help until I understand what you are trying to do.


For search and replace in a large number of files, Perl has a very elegant command-line form:

perl -p -i.bak -e "s/from/to/;" *.txt

Taking it from the right-hand end, it means (1) apply to all files ending in .txt, (2) substitute all text matching 'from' into text 'to', (3) -e execute the script in quotes (4) -i make backup copies of all the files, appending the extension .bak, (5) -p pass through the script for each line in each file.

Is this just what you are looking for?

Ian.