Prev: FAQ 4.11 How do I get a random number between X and Y?
Next: highlight words by regex in pdf files using perl
From: Marc Girod on 21 Feb 2010 06:02 On Feb 20, 11:52 pm, Ben Morrow <b...(a)morrow.me.uk> wrote: > You want the /e switch. I can see that I obviously missed the question, focusing as I did on making sure that the single string in the file I changed would be the one matching the file name, and not even noticing the issue of incrementing the number. So, thanks for the /e switch which I didn't know. Thanks also for the explanation about the .bak files on cygwin. Now, if the files also happen to contain the names of other files in the list, these other lines would be modified as well. We were not told what else the files contain... In fact, I assumed that the first (or an early) line would contain the file name, but that there could be lots of data below, which is why I attempted to close the file after the replacement, which with -pi, wasn't a good idea. a> cat Fife_Ch3.html Fife_Ch0.html Fife_Ch1.html Fife_Ch2.html Fife_Ch3.html a> perl -pi -e 's/^Fife_Ch(\d+)\.html$/$1 + 1/e if /^${ARGV}$/' Fife_Ch*.html a> rm *.bak a> ls -l total 12 -rw-r--r--+ 1 marc None 44 2010-02-21 10:40 Fife_Ch0.html -rw-r--r--+ 1 marc None 44 2010-02-21 10:40 Fife_Ch1.html -rw-r--r--+ 1 marc None 44 2010-02-21 10:40 Fife_Ch2.html -rw-r--r--+ 1 marc None 44 2010-02-21 10:40 Fife_Ch3.html a> cat Fife_Ch3.html Fife_Ch0.html Fife_Ch1.html Fife_Ch2.html 4 Marc
First
|
Prev
|
Pages: 1 2 Prev: FAQ 4.11 How do I get a random number between X and Y? Next: highlight words by regex in pdf files using perl |