Re: Need help w/ reqexp, capture and substitue



Dennis G. Wicks wrote:
Greetings;

Hello,

I frequently have to convert some address books from one format to
another. This is what I need to do.

Input records are like this:

wix@xxxxxxxxxx&Thu Oct 26 07:20:03 2006&1&&&&&&&

The output record needs to be like this:

wix@xxxxxxxxxx&Thu Oct 26 07:20:03 2006&1&wix&&&&&&

In other words, get the user name from the email address and insert it
between the 2 ampersands after the number that follows the year. The
ampersands are field separators
and there will always be an email, a date, and a number.

I can capture the user name and I can substitute something in between
the ampersands, but I can't substitute the user name between the two
ampersands.

Here is what I have up now:

perl -i -p -e 'm/^(.*)?@/;s/\&\&/\&$1\&/;' test.txt

There is a key piece of this that I can't figure out.

Any help greatly appreciated!

perl -pe's/(?=^([^\@]+))((?:[^&]+&){3})/$2$1/' test.txt


perl -ne'
@x = split /&/, $_, -1;
splice @x, 3, 1, ( split /\@/, $x[ 0 ] )[ 0 ];
print join "&", @x;
' test.txt



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Need help w/ reqexp, capture and substitue
    ... Input records are like this: ... The output record needs to be like this: ... get the user name from the email address and insert it between the 2 ampersands after the number that follows the year. ... I can capture the user name and I can substitute something in between the ampersands, but I can't substitute the user name between the two ampersands. ...
    (perl.beginners)
  • Re: OT: Hey guys, I need, like, programmy advice...
    ... >> Right now I do repetitive tasks when I validate and layout files. ... I'm learning Perl now also and it's great. ... >much better ways to do it, but this works for ampersands, and will also ... ># get command line argument: ...
    (alt.internet.search-engines)
  • Re: OT: Hey guys, I need, like, programmy advice...
    ... >>> Right now I do repetitive tasks when I validate and layout files. ... I'm learning Perl now also and it's great. ... >>much better ways to do it, but this works for ampersands, and will also ... I don't use it for replacing ampersands, ...
    (alt.internet.search-engines)
  • Re: OT: Hey guys, I need, like, programmy advice...
    ... > Right now I do repetitive tasks when I validate and layout files. ... I'm learning Perl now also and it's great. ... much better ways to do it, but this works for ampersands, and will also ... print OUTFILE $line; ...
    (alt.internet.search-engines)
  • Re: free source bbs
    ... > MB> IIRC, it was 'Learning Perl' the pink covered book, from about ... Programming Perl - the ampersands for sub calls just stuck over the ...
    (comp.lang.perl.misc)