[ABE.pm] perl regex Q
Faber Fedor
faber at linuxnj.com
Tue Dec 14 15:45:33 CST 2004
I have a text file that contains lines like
1.2,3.4,,5.67,78.9,,,,,0.01
I want to make the line look like this:
1.2,3.4,\N,5.67,78.9,\N,\N,\N,\N,0.01
so I did this:
perl -iBAK -p -e 's/,,/,\\N,/g' foo.txt
Unfortunately, that creates a file that looks like this
1.2,3.4,\N,5.67,78.9,\N,,\N,,0.01
It looks like after the replace, the search starts at the next character
after the previous search term. How do I get around that? There's
prolly a magical switch for that, but I can't find it.
Also, is there a way to do a perl "edit in place" inside of a perl
program other than using backticks (`perl -iBAK -p -e 's/,,/,\\N,/g'
foo.txt`) or the system() call? (No, reading the file in a line at a
time is not an option.)
--
Regards,
Faber
Linux New Jersey: Open Source Solutions for New Jersey
http://www.linuxnj.com
More information about the ABE-pm
mailing list