Reputation: 23441
I am trying to use grep to capture data below:
"\\.xy$" "\\.ab$" "\\.ef\\.hi$"
I have
grep -Eo "((\\\\\.[a-zA-Z]+)){1,2}\\$" file
two problems:
Upvotes: 2
Views: 3627
Reputation: 141810
Precede the dollar with a single backslash:
% grep -Eo '"(\\\\\.[[:alpha:]]+){1,2}\$"' input
"\\.xy$"
"\\.ab$"
"\\.ef\\.hi$"
Or put the special characters into square brackets, which I find more readable:
% grep -Eo '"([\]{2}[.][[:alpha:]]+)+"' input
"\\.xy$"
"\\.ab$"
"\\.ef\\.hi$"
Upvotes: 2
Reputation: 425033
You've double-escaped the $ - try this:
grep -Eo '"((\\\\\.[a-zA-Z]+)){1,2}\$"' file
Upvotes: 0