0

I am trying to grep for a word in a directory - but I want to check for numbers 1-9 in the word.

This is a simple grep:

grep -r L01auxillar /pr/solder/

I want the grep command to search: grep -r L0[1-9]auxillar /pr/solder/

3

3 Answers 3

1

If you don't want to use regexes within grep, you could do the number expansion in the shell:

grep -r --regexp=L0{1..9}auxillar /pr/solder/
Sign up to request clarification or add additional context in comments.

Comments

0

You could use a wildcard for the one character.

grep -rn '/home/user/temp' -e '\<asd.f\>'
# use operator w if you want to catch whole words
grep -rnw '/home/user/temp' -e '\<asd.f\>'

Output:
/home/user/temp/test:1:asd4f
/home/user/temp/test:2:asd5f

But it would also give matches with other chars (eg asd0f or asdgf).

Comments

0

Just pass an -E for extended regex:

grep -rE '(L0[1-9]auxillar)' /pr/solder/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.