Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: grep : partial and/or exact match

by Sidd@786 (Initiate)
on Jun 17, 2020 at 05:51 UTC ( [id://11118170]=note: print w/replies, xml ) Need Help??


in reply to Re: grep : partial and/or exact match
in thread grep : partial and/or exact match

how this partial mismatching is done in this scenario. file1 contents: he/is/man/reg30 don't/you/reg31 what/goes/on/reg32 file2 contents: /is/man/reg30 on/reg32 try/to/do/reg65 output should be: don't/you/reg31

  • Comment on Re^2: grep : partial and/or exact match

Replies are listed 'Best First'.
Re^3: grep : partial and/or exact match
by AnomalousMonk (Archbishop) on Jun 17, 2020 at 07:12 UTC
      my $file1 = \<<"END1"; he/is/man/reg[30] what/goes/on/reg[32] i_am_a_man you_are_reg[60] END1 my $file2 = \<<"END2"; /is/man/reg[30] are_reg[60] try/to/do/reg[65] you/reg[31] END2 open(my $f3, ">", "C:/Users/Siddharth/Desktop/two.txt") or die "Can't open < input.txt: $!"; open my $h2, '<', $file2 or die "cannot open file2"; my %map = <$h2>; my ($regex) = map { qr/$_/ } # 2. join '|', map {quotemeta} close $h2; open my $h1, '<', $file1 or die "cannot open file1"; my @a1= <$h1>; #print grep {$_ =~ $regex} @a1; print $f3 grep {$_ !~ $regex} @a1;

      2020-06-21 Athanasius added code tags.

        i have written above as modified version of previous code(partial mismatching)with the help of reference given by you all as a link,still i am not getting correct output. all lines of file1 are coming as output. whereas output should come as 1. what goes on reg32 2. i_am_a_man please help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11118170]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found