Grep words with special symbols

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












How do I grep this? (Including the special characters)



"Limit reached."[n]"


I tried back-slashing the special symbols but end up not working, like this:



grep '"Limit reached."[\n]" '


I also tried other techniques but also not working. Is there any other syntax you could suggest/advice?










share|improve this question



















  • 1




    is space after last double quote a typos ?
    – Archemar
    Sep 11 at 7:43










  • No, but I also tried with no space
    – Cyril
    Sep 11 at 7:47










  • Double quotes are not paired. Is it normal?
    – Fólkvangr
    Sep 11 at 8:18















up vote
5
down vote

favorite
1












How do I grep this? (Including the special characters)



"Limit reached."[n]"


I tried back-slashing the special symbols but end up not working, like this:



grep '"Limit reached."[\n]" '


I also tried other techniques but also not working. Is there any other syntax you could suggest/advice?










share|improve this question



















  • 1




    is space after last double quote a typos ?
    – Archemar
    Sep 11 at 7:43










  • No, but I also tried with no space
    – Cyril
    Sep 11 at 7:47










  • Double quotes are not paired. Is it normal?
    – Fólkvangr
    Sep 11 at 8:18













up vote
5
down vote

favorite
1









up vote
5
down vote

favorite
1






1





How do I grep this? (Including the special characters)



"Limit reached."[n]"


I tried back-slashing the special symbols but end up not working, like this:



grep '"Limit reached."[\n]" '


I also tried other techniques but also not working. Is there any other syntax you could suggest/advice?










share|improve this question















How do I grep this? (Including the special characters)



"Limit reached."[n]"


I tried back-slashing the special symbols but end up not working, like this:



grep '"Limit reached."[\n]" '


I also tried other techniques but also not working. Is there any other syntax you could suggest/advice?







linux grep special-characters






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 11 at 7:49









Rui F Ribeiro

36.8k1273117




36.8k1273117










asked Sep 11 at 7:37









Cyril

332




332







  • 1




    is space after last double quote a typos ?
    – Archemar
    Sep 11 at 7:43










  • No, but I also tried with no space
    – Cyril
    Sep 11 at 7:47










  • Double quotes are not paired. Is it normal?
    – Fólkvangr
    Sep 11 at 8:18













  • 1




    is space after last double quote a typos ?
    – Archemar
    Sep 11 at 7:43










  • No, but I also tried with no space
    – Cyril
    Sep 11 at 7:47










  • Double quotes are not paired. Is it normal?
    – Fólkvangr
    Sep 11 at 8:18








1




1




is space after last double quote a typos ?
– Archemar
Sep 11 at 7:43




is space after last double quote a typos ?
– Archemar
Sep 11 at 7:43












No, but I also tried with no space
– Cyril
Sep 11 at 7:47




No, but I also tried with no space
– Cyril
Sep 11 at 7:47












Double quotes are not paired. Is it normal?
– Fólkvangr
Sep 11 at 8:18





Double quotes are not paired. Is it normal?
– Fólkvangr
Sep 11 at 8:18











2 Answers
2






active

oldest

votes

















up vote
11
down vote



accepted










use -F in grep



$ cat test.txt
"Limit reached."[n]"
test
"Limit reached."[n]"

$ grep -F '"Limit reached."[n]"' test.txt
"Limit reached."[n]"
"Limit reached."[n]"


As per Manual page,




 -F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by> POSIX,
--fixed-regexp is an obsoleted alias, please do not use it new scripts.)






share|improve this answer




















  • This is good and simple. Thanks!
    – Cyril
    Sep 11 at 8:06










  • There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
    – Marc van Leeuwen
    Sep 11 at 9:47










  • @MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
    – terdon♦
    Sep 11 at 12:44

















up vote
5
down vote













You were very close.



You do not need to excape ", and cannot use shell-escape in single quotes. Therefore all escaping is for grep, not for the shell. (Note on single quotes: single quotes does no interpretation. If you need to put a single quote withing a single quoted string, then you have to come out of single quotes e.g. 'don'''t' )



Test



printf "%s" '"Limit reached."[n]"' | grep '"Limit reached."[\n]"'





share|improve this answer




















  • Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
    – Cyril
    Sep 11 at 8:05










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468192%2fgrep-words-with-special-symbols%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
11
down vote



accepted










use -F in grep



$ cat test.txt
"Limit reached."[n]"
test
"Limit reached."[n]"

$ grep -F '"Limit reached."[n]"' test.txt
"Limit reached."[n]"
"Limit reached."[n]"


As per Manual page,




 -F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by> POSIX,
--fixed-regexp is an obsoleted alias, please do not use it new scripts.)






share|improve this answer




















  • This is good and simple. Thanks!
    – Cyril
    Sep 11 at 8:06










  • There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
    – Marc van Leeuwen
    Sep 11 at 9:47










  • @MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
    – terdon♦
    Sep 11 at 12:44














up vote
11
down vote



accepted










use -F in grep



$ cat test.txt
"Limit reached."[n]"
test
"Limit reached."[n]"

$ grep -F '"Limit reached."[n]"' test.txt
"Limit reached."[n]"
"Limit reached."[n]"


As per Manual page,




 -F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by> POSIX,
--fixed-regexp is an obsoleted alias, please do not use it new scripts.)






share|improve this answer




















  • This is good and simple. Thanks!
    – Cyril
    Sep 11 at 8:06










  • There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
    – Marc van Leeuwen
    Sep 11 at 9:47










  • @MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
    – terdon♦
    Sep 11 at 12:44












up vote
11
down vote



accepted







up vote
11
down vote



accepted






use -F in grep



$ cat test.txt
"Limit reached."[n]"
test
"Limit reached."[n]"

$ grep -F '"Limit reached."[n]"' test.txt
"Limit reached."[n]"
"Limit reached."[n]"


As per Manual page,




 -F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by> POSIX,
--fixed-regexp is an obsoleted alias, please do not use it new scripts.)






share|improve this answer












use -F in grep



$ cat test.txt
"Limit reached."[n]"
test
"Limit reached."[n]"

$ grep -F '"Limit reached."[n]"' test.txt
"Limit reached."[n]"
"Limit reached."[n]"


As per Manual page,




 -F, --fixed-strings, --fixed-regexp
Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched. (-F is specified by> POSIX,
--fixed-regexp is an obsoleted alias, please do not use it new scripts.)







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 11 at 7:55









Kamaraj

2,9081413




2,9081413











  • This is good and simple. Thanks!
    – Cyril
    Sep 11 at 8:06










  • There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
    – Marc van Leeuwen
    Sep 11 at 9:47










  • @MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
    – terdon♦
    Sep 11 at 12:44
















  • This is good and simple. Thanks!
    – Cyril
    Sep 11 at 8:06










  • There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
    – Marc van Leeuwen
    Sep 11 at 9:47










  • @MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
    – terdon♦
    Sep 11 at 12:44















This is good and simple. Thanks!
– Cyril
Sep 11 at 8:06




This is good and simple. Thanks!
– Cyril
Sep 11 at 8:06












There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
– Marc van Leeuwen
Sep 11 at 9:47




There is also the fgrep command, which as per the manpage does just grep -F. Personally I always use fgrep unless I know I am really using a regexp.
– Marc van Leeuwen
Sep 11 at 9:47












@MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
– terdon♦
Sep 11 at 12:44




@MarcvanLeeuwen it might be a good idea to get used to grep -F since fgrep and egrep are only included for backwards compatibility now that POSIX specifies -F and -E.
– terdon♦
Sep 11 at 12:44












up vote
5
down vote













You were very close.



You do not need to excape ", and cannot use shell-escape in single quotes. Therefore all escaping is for grep, not for the shell. (Note on single quotes: single quotes does no interpretation. If you need to put a single quote withing a single quoted string, then you have to come out of single quotes e.g. 'don'''t' )



Test



printf "%s" '"Limit reached."[n]"' | grep '"Limit reached."[\n]"'





share|improve this answer




















  • Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
    – Cyril
    Sep 11 at 8:05














up vote
5
down vote













You were very close.



You do not need to excape ", and cannot use shell-escape in single quotes. Therefore all escaping is for grep, not for the shell. (Note on single quotes: single quotes does no interpretation. If you need to put a single quote withing a single quoted string, then you have to come out of single quotes e.g. 'don'''t' )



Test



printf "%s" '"Limit reached."[n]"' | grep '"Limit reached."[\n]"'





share|improve this answer




















  • Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
    – Cyril
    Sep 11 at 8:05












up vote
5
down vote










up vote
5
down vote









You were very close.



You do not need to excape ", and cannot use shell-escape in single quotes. Therefore all escaping is for grep, not for the shell. (Note on single quotes: single quotes does no interpretation. If you need to put a single quote withing a single quoted string, then you have to come out of single quotes e.g. 'don'''t' )



Test



printf "%s" '"Limit reached."[n]"' | grep '"Limit reached."[\n]"'





share|improve this answer












You were very close.



You do not need to excape ", and cannot use shell-escape in single quotes. Therefore all escaping is for grep, not for the shell. (Note on single quotes: single quotes does no interpretation. If you need to put a single quote withing a single quoted string, then you have to come out of single quotes e.g. 'don'''t' )



Test



printf "%s" '"Limit reached."[n]"' | grep '"Limit reached."[\n]"'






share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 11 at 7:55









ctrl-alt-delor

9,20431948




9,20431948











  • Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
    – Cyril
    Sep 11 at 8:05
















  • Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
    – Cyril
    Sep 11 at 8:05















Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
– Cyril
Sep 11 at 8:05




Thank you for this. This works also but on the real logs file, doesn't work. Good explanation though.
– Cyril
Sep 11 at 8:05

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f468192%2fgrep-words-with-special-symbols%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?