in reply to Parse a text file with oneliner
Have a look at perlrun and the -F switch, it's similar to awk, except it splits into the array @F:
perl -F: -lane 'print $F[0] if /^[A-Z]/' infile
Now you could pipe that through sort, or with some trickery you can have Perl do that for you too (see the "Eskimo greeting" in perlsecret):
perl -F: -lane 'push @x, $F[0] if /^[A-Z]/}{print for sort @x' infile
This should produce the same output as your first grep | awk | sort command.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parse a text file with oneliner
by RenMcCourtey (Acolyte) on Aug 28, 2017 at 10:08 UTC | |
by haukex (Archbishop) on Aug 28, 2017 at 10:20 UTC | |
by RenMcCourtey (Acolyte) on Aug 28, 2017 at 12:07 UTC | |
Re^2: Parse a text file with oneliner
by RMGir (Prior) on Aug 28, 2017 at 14:00 UTC |