winter67uk has asked for the wisdom of the Perl Monks concerning the following question:
I have a long string, something like this:
AAA+XXXX+1234++here?'s some text+eol1'BBB+XXXX+1234++here?'s some text+eol2'CCC+XXXX+1234++here?'s some text+eol3'etc.
I would like to parse the string by inserting a new line (\n) after each apostrophe (the line terminator). Unfortunately some apostrophes are escaped by a question mark, meaning they are part of a text field. I tried this:
perl -ne "s/[^?]'/\'\n/g" && print" input.txt
...which doesn't work. It loses the last character from each line because the substitution matches two characters, not one. Can someone suggest a simple one-liner that doesn't drop the last character in each line?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple Substitution
by dragonchild (Archbishop) on Jan 13, 2005 at 17:54 UTC | |
by winter67uk (Initiate) on Jan 14, 2005 at 10:42 UTC | |
by winter67uk (Initiate) on Jan 18, 2005 at 11:22 UTC | |
|
Re: Simple Substitution
by TedYoung (Deacon) on Jan 13, 2005 at 17:54 UTC | |
|
Re: Simple Substitution
by friedo (Prior) on Jan 13, 2005 at 17:58 UTC | |
|
Re: Simple Substitution
by ww (Archbishop) on Jan 13, 2005 at 18:38 UTC | |
|
Re: Simple Substitution
by holli (Abbot) on Jan 13, 2005 at 17:55 UTC | |
|
Re: Simple Substitution
by ambrus (Abbot) on Jan 13, 2005 at 20:22 UTC | |
by winter67uk (Initiate) on Jan 14, 2005 at 10:56 UTC |