sed - find specific names in unix -


i want print cities fulfill 3 conditions: capital, clean , big.

input:

london big city london capital london clean city ohio big city sydney big city sydney clean city canberra capital canberra big city canberra clean city newyork big city newyork clean city 

output:

london canberra 

i need names fulfill 3 conditions: capital, clean , big.

i tried cut first column in separate file each city grep name file|wc -l , take have count more 3. how can done in unix using sed or awk.

just fun.

the shell hacker's solution:

sort -u input.txt | cut -d' ' -f1 | uniq -dc | egrep '^\s+3\s' 

the perl hacker's solution:

#!/usr/bin/perl use strict; use warnings; use constant {     capital => 1,     clean   => 2,     big     => 4, }; %table;  while(<>) {     print stderr "unparsed: $_" unless m/^(\w+)\s+is a\s+((big city)|(clean city)|(capital))\s*$/gio;      $table{$1} |= defined($3) * big +                   defined($4) * clean +                   defined($5) * capital; }  while (my ($k,$v) = each %table) {     print "$k\n" if (capital+clean+big) == $v; } 

Comments

Popular posts from this blog

javascript - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -