This is my text file:
line A line B line C Now I'm trying to find the line that ends with A:
cat foo.txt | grep 'A$' BTW:
$ grep --version GNU grep 2.6.3 There is nothing wrong with your grep command. But there may be a chance of space characters exists after the last A. so use the below grep command.
grep 'A\s*$' file \s matches any kind of horizontal or vertical whitespace character.
OR
You could use the POSIX character class [[:space:]] to match any kind of space character.
grep 'A[[:space:]]*$' file \s only works in newer versions of GNU grep. Use [[:space:]] for portability.
cat -e foot.txtdo you see^Mor$?