AShah
AShah

Reputation: 942

grep hashed out line from file

I want to exact match the below line in a file

#dtoverlay=piscreen,drm

I have tried

grep "\#dtoverlay=piscreen,drm\" /boot/config.txt

but this also returns a match for

##dtoverlay=piscreen,drm

Also tried with a -w, but it also matches ##dtoverlay=piscreen,drm

grep -w '#dtoverlay=piscreen,drm' /boot/config.txt
##dtoverlay=piscreen,drm

Upvotes: -1

Views: 52

Answers (2)

Timur Shtatland
Timur Shtatland

Reputation: 12425

Use this regex, where ^ and $ match the beginning and the end of the line, respectively:

grep '^#dtoverlay=piscreen,drm$' /boot/config.txt

See grep manual:

Anchoring

The caret ^ and the dollar sign $ are meta-characters that respectively match the empty string at the beginning and end of line.

Upvotes: 1

KamilCuk
KamilCuk

Reputation: 141698

Use:

grep -Fx '#dtoverlay=piscreen,drm'

Upvotes: 2

Related Questions