analys has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I was trying to extract the following words (b and f sentence - b should only be from f sentence ) from input file. But I'm not sure what's the correct regex for the following codes.Sorry about that, I have edited the output description.
My code :
open (INPUT, "<", $ARGV[0]) || die "\nError: File Read \"$ARGV[0]\"\nE +rror: $!\n\n"; while ( $line = <INPUT> ) { if ( $line =~ /^(b|f)/) { print $line; } } close INPUT;
Input file : (to extract for b and f)
b=23 y=0x11 arg=0x70 def=0x1 val=0x234 checking system b=71 y=0x35 arg=0x87 def=0x3 val=0x76d h=reg.k2.io.chk 0x2001 b=54 y=0x23 arg=0x78 def=0x2 val=0x65b f chk.fin.reg.m_cwr 0x213 b=54 y=0x23 arg=0x78 def=0x2 val=0x65b checking system b=40 y=0x90 arg=0x34 def=0x5 val=0x2197 f ref.grf.pin.clk_trg 0x0021
Expected output:
b=54 y=0x23 arg=0x78 def=0x2 val=0x65b f chk.fin.reg.m_cwr 0x213 b=40 y=0x90 arg=0x34 def=0x5 val=0x2197 f ref.grf.pin.clk_trg 0x0021 The b must be from f From the b and f I want to get the from b (y, arg and def) and f (\w+ - chk.fin.reg.m_cwr /ref.grf.pin.clk_trg )
2018-03-12 Athanasius added code and paragraph tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl regex for repeating words
by Perlbotics (Archbishop) on Mar 11, 2018 at 18:36 UTC | |
by analys (Initiate) on Mar 12, 2018 at 14:04 UTC | |
by Marshall (Canon) on Mar 13, 2018 at 12:48 UTC | |
|
Re: perl regex for repeating words
by Marshall (Canon) on Mar 11, 2018 at 17:50 UTC | |
|
Re: perl regex for repeating words
by AnomalousMonk (Archbishop) on Mar 11, 2018 at 20:15 UTC |