Score:0

Does grep and friends have a way to match strings as if shell file name globbing in stead of regex

cx flag

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??.*"

hr flag
Related: [Can globbing be used to search file contents?](https://askubuntu.com/questions/1445515/can-globbing-be-used-to-search-file-contents)
Score:0
cn flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.