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?
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.
|
|---|