0

これが私がやろうとしていることです:

$variable = `grep -i "Text: Added to directory" '$FOO/result.txt' | awk '{print $6}' | tr -d "'"`
print $variable;

出力:

Text: Added to directory /path/to/directory/
Use of uninitialized value $6 in concatenation (.) or string

「テキスト:ディレクトリ/ path / to / directory/に追加」の代わりに「/path / to / directory」だけをフェッチするにはどうすればよいですか?

4

2 に答える 2

4

もちろん、Perlはgrep、awk、trが実行できることを実行できます。

open my $fh, "<", "$FOO/result.txt" or die "can't open file: $!\n";
while (<$fh>) {
    next unless /pattern/i;
    (my $six = (split)[5]) =~ tr/'//d;
    print $six, "\n";
}
close $fh;
于 2012-12-05T18:54:54.037 に答える
1

おそらく引用符のエスケープを調整する必要がありますが、これは次のことを行う必要があります。

awk IGNORECASE=1 '/yourpattern/{ gsub(/\'/, \'\'); print $6 }' $FOO/result.txt

AWKはかなり用途が広いです。

于 2012-12-05T19:10:45.690 に答える