Issue
I want to grep a file with a word, say "AAA", and it ends with whitespace or newlines. I know how to write this seperately, as follows, but having problems in combining them (in the sense that it outputs both VVV AAA
and AAA VVV
).
$echo -e "AAA VVV \nVVV AAA\nBBB" | grep "AAA$"
>VVV AAA
$echo -e "AAA VVV \nVVV AAA\nBBB" | grep "AAA[[:space:]]"
>AAA VVV
I have tried using []
, but without success..
Solution
If you are looking for word AAA
followed by space anywhere in the string, or at the end of line, then use
grep -P "AAA( |$)"
Answered By - Ωmega