Reputation: 15
This is what I'm trying to do:
$variable = `grep -i "Text: Added to directory" '$FOO/result.txt' | awk '{print $6}' | tr -d "'"`
print $variable;
Output:
Text: Added to directory /path/to/directory/
Use of uninitialized value $6 in concatenation (.) or string
How can I fetch just "/path/to/directory" instead of "Text: Added to directory /path/to/directory/"?
Upvotes: 0
Views: 6321
Reputation: 3484
You probably need to adjust the quote-escaping but this should do:
awk IGNORECASE=1 '/yourpattern/{ gsub(/\'/, \'\'); print $6 }' $FOO/result.txt
AWK is pretty versatile.
Upvotes: 1
Reputation: 246744
Of course Perl can do what grep, awk and tr can do.
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;
Upvotes: 4