I'm trying to get the filename from unrar command verbose and deleting them all through command line.
The unrar command output is similar to this:
Extracting BucketSort.cpp OK
Extracting BucketSort.vcxproj OK
Extracting BucketSort.vcxproj.filters OK
Extracting BucketSort.lastbuildstate OK
Extracting BucketSort.log OK
Extracting BucketSort.obj OK
Extracting BucketSort.pch OK
So I came up with this awk command so far:
unrar e BucketSort.rar | awk '{if (match($0,/Extracting\s*([\w|.]+)\s*OK/,m)) print m[0]}'
but nothing is printed. When I leave just the word "Extracting" to match I can see "Extracting" for all the extracting files. So it's not recognizing something written in regex but I don't know what it is. Do you know what's wrong with the expression?
PS: You can check the regex expression here.
awk
you need to backslash-escape a lot more of the "special" bits of regexes, including parentheses, and (I believe)+
as well. – Wildcard Feb 11 at 20:01match
) supports the perl-like\s
and\w
classes, however it's not clear to me how[\w|.]
should be interpreted. Regardless, it seems to be a heavy-handed way to split what appear to be simple whitespace delimited fields - why not just do$1=="Extracting" && $3=="OK"
– steeldriver Feb 11 at 20:59\w
inside brackets (although I can't find documentation to support this claim). Both of these provide the output you seek:(\S+)
and([[:alnum:]_.]+)
. references gnu.org/software/gawk/manual/html_node/… and gnu.org/software/gawk/manual/html_node/Bracket-Expressions.html – glenn jackman Feb 11 at 22:20