How to grep for the pattern at the end of the line?

String at the ending of a line can be grep-ed by suffixing a dollar($) symbol to the pattern.

grep pattern$ My-Filename
# ($), dollar symbol

Here is an example

dev@codetryout:~$ grep host$ /etc/hosts
127.0.0.1	localhost
dev@codetryout:~$ 

Grep pattern at the ending of the line, case insensitive

dev@codetryout:~$ grep -i Hosts$ /etc/hosts
# The following lines are desirable for IPv6 capable hosts

Grep output to display the line number in the result

dev@codetryout:~$ grep -in Hosts$ /etc/hosts
4:# The following lines are desirable for IPv6 capable hosts
dev@codetryout:~$ 

Here is another example with multiple output lines, grep-ing for lines ending with the character s

dev@codetryout:~$ grep -in s$ /etc/hosts
4:# The following lines are desirable for IPv6 capable hosts
8:ff02::1 ip6-allnodes
9:ff02::2 ip6-allrouters
dev@codetryout:~$ 

We have just explored several ways to grep pattern at the beginning of a text file