0

Effectively I'm trying to search a text file containing "file names" and want to match as if shell file globbing were in effect.

Shell file globbing is much simpler than regular expressions, so I need some kind of

grep "data??.*" < list_of_filenames

And bonus points if I can do it with AWK, eg something along the lines of

awk -F/ '$NF ~ /data??.*/ {print $0}' < list_of_filenames

to print the line when the last part of the line delimited by / matches the patern "data??.*"

1 Answers1

0

Anything globs can do can also be expressed as a regular expression. So although the answer to your question is no, tools like grep only do strings and regular expressions, that shouldn't be a problem. Regexes are a much more pwoerful tools than globs.

For the example in your question where you want something that begins with data, then any two characters, then a . and then 0 or more characters until the end of the line (that's what your expression would match if used as a glob), the equivalent regular expression is:

^data..\..*

So you can use that in grep or in awk (you don't need the print, by the way, the default action when something evaluates to true in awk is to print the current line):

awk -F/ '$NF ~ /^data..\..*/' list_of_filenames
terdon
  • 100,812