Regex: Line Begin Anchor
Regular Expression Line Begin Anchor: ^
You can match the beginning of a line with the Regular Expression line begin anchor: ^
.
Earlier grep 'Paul'
matched lines that had 'Paul'
at any point in the line. If you want to match 'Paul'
at the very beginning of each line you could use the line begin anchor: ^
.
Match '^Paul'
grep '^Paul' user.csv
Output:
Take note that Bianca,Paul,...
is not in our matched lines.
Match '^Paul,'
grep '^Paul,' user.csv
Output:
Take note that Paula,Richardson,...
is not in our matched lines.
Note
Using the RegEx line begin anchor you have already created a pattern that is more effective than just searching for the string by itself.