I have the following data from which I mean to extract only those lines which contain "bb" only. Not "b" or "bbb" or anything else just "bb".
abb
abbb
aabbcc
aabab
abbbbc
Now when I use the following combination of commands-:
cat file1 | grep "bb[^b]
I am getting the output as all the lines in my sample file-:
abb
abbb
aabbcc
aabab
abbbbc
The expected I want is -:(The lines that contain only "bb")
abb
aabbcc
What is the regular expression that can achieve this ?
abbbabb is not valid. I am looking for lines that contain only bb and no other pattern of b. The line will contain only two, consecutive b and no other b characters at all.
abbbcbb
??bbabb
is valid andabbacbbcabb
is not valid in your case? hard to understand. Please edit your question to including all possible ways that you want to get. your input example is not clear and not enough good.grep '^[^b]*bb[^b]*$' file
already mentioned by PM.