in reply to Simple Text Manipulation
I can’t use a simple search and replace because the Article numbers change. Can Perl be used to do this?
Well fortunately Perl doesn't restrict you to simple search and replace, instead you have arguably the most powerful regular expression engine in the known universe! Perlre's eat changing numbers for breakfast whilst blindfolded with all eight limbs tied behind their backs. Some suggestions to add to Corion's sage advice:
- figure out exactly how you identify the lines you want to change. Corion had to assume they were all starting with Article since you weren't specific about that
- decide exactly how the lines may be constructed: are they always just letters and spaces, or may they have numerals, punctuation, carriage returns?
As a trivial solution I offer this simple modification of JavaFan's solution which you would apply line by line as you read through the file, but note it will not work if you have a different specification for the lines. I prefer to be as specific as I can in regular expressions, so know your data.
s/^(Article\s+[0-9]+\s+[\w\s]+$)/\\subsection*{$1}/;
--
I'd like to be able to assign to an luser
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Simple Text Manipulation
by Anonymous Monk on Feb 05, 2011 at 18:40 UTC | |
by Anonymous Monk on Feb 05, 2011 at 18:44 UTC | |
by Anonymous Monk on Feb 05, 2011 at 19:41 UTC | |
by Corion (Patriarch) on Feb 05, 2011 at 19:47 UTC | |
Re^2: Simple Text Manipulation
by pseingalt (Initiate) on Feb 06, 2011 at 11:08 UTC | |
by Corion (Patriarch) on Feb 06, 2011 at 11:12 UTC | |
by Albannach (Monsignor) on Feb 06, 2011 at 19:43 UTC |
In Section
Seekers of Perl Wisdom