in reply to Re: How do i replace one variable with another after searching for a pattern
in thread How do i replace one variable with another after searching for a pattern

I want the output in this way:

JDW-HP 1MVWV93V7j2Hxsa0Ag6 24:00:00 SUBJECT_EXACT _Did you160serve our160country? -New VA Home.Loan Program_

JDW-HP 1MVWV98Ddd4fLsa0Ag6 24:00:00 SUBJECT_EXACT Did.you.serve_our country? New-VA Home160Loan Program_

  • Comment on Re^2: How do i replace one variable with another after searching for a pattern

Replies are listed 'Best First'.
Re^3: How do i replace one variable with another after searching for a pattern
by AppleFritter (Vicar) on Jul 31, 2014 at 18:27 UTC

    Even easier. Same as above, but the regex simplifies to:

    s/<([0-9A-F]+)>/hex($1)/eg;
      stummala@sa-mua01:/home/stummala/scripts$./samp2 Can't locate feature.pm in @INC (@INC contains: /home/gsapan/perl5/lib +/perl5/sun4-solaris-thread-multi /home/gsapan/perl5/lib/perl5/x86_64- +linux-thread-multi /home/gsapan/perl5/lib/perl5 /usr/lib64/perl5/site +_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 +/usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib64/pe +rl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor +_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64- +linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./samp2 line 4. BEGIN failed--compilation aborted at ./samp2 line 4.

        Ah, you're using an ancient perl. Simply leave out the use feature qw/say/; line, and replace say; in the loop body with a print statement:

        while(<DATA>) { chomp; s/<([0-9A-F]+)>/hex($1)/eg; print "$_\n"; }

        Actually, you could probably also get away with not chomping your input in the first place here:

        while(<DATA>) { s/<([0-9A-F]+)>/hex($1)/eg; print; }

        And at this point, assuming you merely want to output the results and do nothing further with them in this particular script, the whole script can be turned into a oneliner you can directly enter on the command line. Using perl's -p switch (see perlrun):

        $ perl -pe 's/<([0-9A-F]+)>/hex($1)/eg' /home/stummala/a JDW-HP 1MVWV93V7j2Hxsa0Ag6 24:00:00 SUBJECT_EXACT _Did you160serve our +160country? -New VA Home.Loan Program_ JDW-HP 1MVWV98Ddd4fLsa0Ag6 24:00:00 SUBJECT_EXACT Did.you.serve_our co +untry? New-VA Home160Loan Program_ $