Mark Seliaev
Mark Seliaev

Reputation: 570

Regex doesn't work in grep

Try search for filenames in file.txt with this regexp: ([\w.-]+)[.]\w+/gm On regexr.com it works good, but when I try to find them with grep with this command I get nothing:

grep -E "([\w.-]+)[.]\w+/gm" file.txt

What am I doing wrong?

Input:

hello.py fasdfasdf
fadsfsdf
f
file.docx fsdfasdf
fadsfsdf.fds
FILE.mp3

Output:

hello.py
file.docx
fadsfsdf.fds
FILE.mp3

Upvotes: 0

Views: 813

Answers (1)

chepner
chepner

Reputation: 530960

\w is a Perl extension; either use the -P option with grep (if supported), or use a standard regular expression instead:

grep -E '([[:alpha:].-]+)[.][[:alpha:]]+/gm' file.text

Upvotes: 1

Related Questions