Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Need to multi grep and grep exclude in perl.

by Random_Walk (Prior)
on Feb 23, 2016 at 08:55 UTC ( [id://1155893]=note: print w/replies, xml ) Need Help??


in reply to Need to multi grep and grep exclude in perl.

cat file.large | ggrep country | ggrep city1 | ggrep street1 | ggrep -v name1

Horrilbe, I know.... but need to get the value of name2 only as output. File text looks sort of:

So do you know the value of name1 in advance to be removing it from the output, or do you want to discard the first name and display the second, for each country/city/street/number match?

Update

Here is some code that prints the second name at an address, ignoring the first name, and any third, fourth,...

use strict; use warnings; my %seen; # here we note addresses we saw already while (<DATA>){ my ($country, $city, $street, $number, $name) = split; next unless ++$seen{$country}{$city}{$street}{$number} == 2; print "Second name at $city, $country, $street, $number is $name\n +"; } __DATA__ Country City1 Street1 number1 name1 Country City1 Street1 number1 name2 Country City1 Street1 number2 name3 Country City1 Street2 number1 name4 Country City1 Street2 number1 name5

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found