0

A purely grep question.

A file contains commented out strings. For example:

abc
abc1
# def3
ghi5
qwe

I want to get all strings with a number in it, but not if this string prepended with "#". So in this example we should see

abc1
ghi5

The double grep solves the problem:

grep -vE "^#" file.txt | grep -E "[0-9]"

Now the question: Is there a way to do that in one run of grep?

1 Answer 1

1

If you can be sure that the first character is a letter (you did not check for that either):

grep '^[^#].*[0-9]' file.txt
1
  • A corner case of single digit lines will not be caught. Commented Aug 8, 2020 at 5:39

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.