I'm trying to use grep files in a Linux directory searching for lines which contain the string **Post
. The * character is a wildcard, and I can't figure out how to make it literal for this search. For example \*\*Post
doesn't work. What's the proper way of escaping the * character so it can be used literally in this case?
Asked
Active
Viewed 609 times
0

Doug Lerner
- 1,383
- 2
- 17
- 36
1 Answers
1
I tested with a file containing the following text:
**Post
*Post
Post
And I would like to grep only the one with **Post
My command is the following
grep -irn "\*\*Post"
The double quote is important.
The result of the command is
a.txt:1:**Post
While the following command
grep -irn "\*Post"
outputs
a.txt:1:**Post
a.txt:2:*Post

Pat. ANDRIA
- 2,330
- 1
- 13
- 27
-
I'm trying your command with my files which begin with `log` like this: `grep -irn "\*\*Post" log*` and what I'm getting are a bunch of lines containing the characters `grep`! – Doug Lerner Nov 14 '20 at 11:19
-
In my case, my filename is `a.txt` so, i can do `grep -irn "\*\*Post" a*` and it still gives me the correct output. And I even tried to duplicate the files, I still receive the correct output. What is the content of your file? Can you provide a minimal content? – Pat. ANDRIA Nov 14 '20 at 11:23
-
I don't know which file contains the pattern. But they are long log files with a bunch of lines that look like `* 0020003802 6600000000 000090ED40 02359C1D01 85ED40023E . .8.f......??@.5?..??@.>` – Doug Lerner Nov 14 '20 at 11:25
-
What is exactly the ouput when you execute the grep command? – Pat. ANDRIA Nov 14 '20 at 11:27
-
1Never mind. I had an extra `grep` in my command line. Your solution works. Thanks very much. – Doug Lerner Nov 14 '20 at 11:31