Regex: Line End Anchor

Regular Expression Line End Anchor: $

You can match the end of a line with the Regular Expression line end anchor $.

In the case of this specific data-set company names come at the end of each line.

Match 's$'

Let’s match all lines that end with the letter s:

grep 's$' user.csv

Output:

grep ’s$’ output

Any line that ends with the letter s has been matched, in the case of this dataset Express Scripts and Edward Jones both match our provided pattern.

Match 'Accenture$'

Since the last entry in each record is a company name let’s match all records that have Accenture as the company:

grep 'Accenture$' user.csv

grep ‘Accenture$’

Every line that ends with Accenture is a part of the output from this grep command.

Note

This is another simple RegEx concept and syntax you can use to create better matching patterns.