I need to find file from ls - l by using grep and certain regexp.

In particular I need greep to see certain file ending, like let's say .txt but only using regex.

So it should be something like

ls -l | grep '^.+\.txt$'

But that doesn't seem to work for me.

link|improve this question

1  
Is there a reason you are not using ls -l *.txt? Also note that with the eoln match ($), this will not pick up symlinks. With extended regexp (as Matt mentions), you might want to use '^.+\.txt\>' $ ls -l *.txt lrwxrwxrwx 1 arcege arcege 8 2011-04-07 09:04 file.txt -> realfile $ ls -l | grep -E '^.+\.txt$' $ ls -l | grep -E '^.+\.txt\>' lrwxrwxrwx 1 arcege arcege 8 2011-04-07 09:04 file.txt -> realfile – Arcege Apr 7 '11 at 13:06
feedback

1 Answer

up vote 4 down vote accepted

You need to specify the -E flag for grep:

-E, --extended-regexp
    Interpret  PATTERN  as  an extended regular expression (ERE, see
    below).  (-E is specified by POSIX.)
link|improve this answer
Hm.. Damn inattentiveness, I tried it but didn't specify the correct path :D – den-javamaniac Apr 7 '11 at 10:21
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.