ak44
ak44

Reputation: 69

find exact match of letters using grep

I got a one little problem. I have few files:

hello-1.c
hello-1.o
hello-2..c
hello-2.o
hello-3.c
Makefile
testorder

and using grep I want to obtain only files which contain one letter "e".

When I try this way:

ls | grep "e\{1\}

it still give me i.e Makefile. For any reply thanks in advance.

Upvotes: 2

Views: 76

Answers (1)

If the files are listed in a file, you can use grep "^[^e]*e[^e]*$". This will hit instances that start with zero or more non-e characters, have an e in them, and end with zero or more non-e characters.

If the files are in a directory, you should use find . -regex '^[^e]*e[^e]*$'

Upvotes: 2

Related Questions