Reputation: 5434
i have a file with the following line:
s:15:\"https://cnn.com\"
cat myfile.txt | grep https://cnn.com
works.
But I'd like to find the s:15
portion too as well so I try:
cat myfile.txt | grep 's:15:\"https://cnn.com\"'
Zero results. What am I doing wrong?
Upvotes: 0
Views: 844
Reputation: 330
The problem with using '\"' is that you are doubling down on having the shell process your quote. You either need to backslash just the quote character \"
or use the single quotes without backslash '"'
. Doing both will have grep searching for a backslash and a quote.
Try
grep s:15:\"https://cnn.com\"
or
grep 's:15:"https://cnn.com"'
Edit: My above answer is incorrect due to there being backslash characters in the data. Since grep uses a backslash as an escape character, you need to provide it with a double backslash to match a single occurrence.
Upvotes: 1
Reputation: 23015
The issue with your command is not the quotes but the backslashes. As you have the backslashes in your original file, you need to match the backslashes with grep too (so, escape them):
$ cat myfile.txt | grep 's:15:\\"https://cnn.com\\"'
s:15:\"https://cnn.com\"
Upvotes: 2