in reply to Condition on multiple lines and big file
G'day epimenidecretese,
"I'm not sure if perl it's the right tool for it."
Perl would be an admirable tool for this task.
#!/usr/bin/env perl use strict; use warnings; while (<DATA>) { my ($name, $code) = (split)[0,-1]; print $code eq 'I-GPE' ? " $name" : $. == 1 ? $name : "\n$name"; } print "\n"; __DATA__ Buenos - SPN Buenos B-GPE Aires - SPN Aires I-GPE Afghanistan - SPN Afghanistan B-GPE Europa - SPN Europa B-GPE UE - I UE B-GPE Italia - SPN Italia B-GPE Provincia - SS Provincia B-GPE di - E di I-GPE Lucca - SPN Lucca I-GPE
Output:
Buenos Aires Afghanistan Europa UE Italia Provincia di Lucca
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Condition on multiple lines and big file
by VincentK (Beadle) on Dec 06, 2013 at 20:09 UTC |