質問にperlのタグを付けたので、その例をいくつか示します。
Perlでハードコードされています:
#!/usr/bin/perl
use warnings;
use strict;
open INFILE,"<somefilename";
while (<INFILE>)
{
my @cols = split(/\s+/,$_);
if ($cols[0] eq '10993') { print $cols[-1] . "\n"; }
}
再びperlを使用しますが、代わりにSTDINから取得するため、出力をパイプするだけで済みます。
#!/usr/bin/perl
use warnings;
use strict;
while (<>)
{
my @cols = split(/\s+/,$_);
if ($cols[0] eq '10993') { print $cols[-1] . "\n"; }
}
perlのさらに別の例では、ファイル名を最初の引数として、必須の最初のフィールドを2番目の引数として使用します。
#!/usr/bin/perl
use warnings;
use strict;
unless ($ARGV[0]) { die "No filename specified\n" }
unless ($ARGV[1]) { die "No required field specified\n" }
unless (-e $ARGV[0]) { die "Can't find file $ARGV{0]\n" }
open INFILE,"<ARGV{0]";
while (<INFILE>)
{
my @cols = split(/\s+/,$_);
if ($cols[0] eq $ARGV[1]) { print $cols[-1] . "\n"; }
}
ただし、awkを使用する方がおそらく簡単です。
awk '{if ($1 == 10993) {print $NF}}' someFileName