Tags

,

Requirement : Obtain line no and first field (if it is a number) from the following datafile

31726108012^Abicyclepatrolpuyallup^A0^B
31726228012^Acommercialguardseattlesecurity^A0^B
31726230512^Aconstructionguardkentsecurity^A0^B
31726241512^Aeventfederalguardsecurityway^A0^B

^A indicates ctrl + A

perl -n -e ‘@line= split /^A/,$_ ; if (int($line[0]) != 0) { print “$. ” . $line[0] .”\n” }’ datafile

$. gives us the line no.
int(any non numeric value) will return 0.

To generate ctrl A use the following key combination ctrl + v + a. The output generated will be as follows :

5 31726228012
6 31726230512
7 31726241512
8 31726254012

Advertisements