0

I create the following text and when you want to search for the pattern "10?", it doesn't recognize anything, let's see:

ubuntu@ip-172-31-30-142:~$ cat > demo1.txt
10 1 101 10
1
10
101
1010111
10
1 10
1 1 1 1 10
1 1
1 0
0 10
1
ubuntu@ip-172-31-30-142:~$ cat demo1.txt
10 1 101 10
1
10
101
1010111
10
1 10
1 1 1 1 10
1 1
1 0
0 10
1
ubuntu@ip-172-31-30-142:~$ grep "10?" demo1.txt
ubuntu@ip-172-31-30-142:~$

Why doesn't it recognize the pattern set in the regular expression?

enter image description here

  • 2
    See [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – steeldriver Nov 12 '22 at 01:25

1 Answers1

3

The ? special character is part of extended regular expressions. grep -E "10?" demo1.txt should return the result you're looking for.

David Yockey
  • 1,653
  • 7
  • 12