Reputation: 113
for example, i want to match the string "abcabc" in a text file, where the two (and only two) "abc" are attached together, and no characters are in front of and at the end of "abcabc"?
if i use grep -n '(abc){2}' TEST, it does not work
Upvotes: 0
Views: 109
Reputation: 113
Thanks guys, from your answers, i think i have got what i need.
As i said in my questions, i want to match "abcabc
", where 2 and only repeated "abc
", no other characters in front of and at the end of, but "abcabc
" is not the only string in that line.
so the answers is:
grep -n "\b\\(abc\\)\\{2\\}\b" filename
Upvotes: 0
Reputation: 3037
Check this fits.
$ grep '\<abcabc\>'
test
abcabc
abcabc
test abcabc
test abcabc
testabcabc
Upvotes: 0
Reputation: 19204
Escape the parentesis:
grep -n '\(abc\)\{2\}' TEST
if you want to match the string abcabc
alone on a line, as your description seems to suggest, use:
grep -n '^\(abc\)\{2\}$' TEST
Upvotes: 1