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 回答