linux - HOW to solve the point in Regex? -
the file is:
google.com go.gle.com google.com.google.com b google.com.cloud.com c
when use way:
grep -nre '^\<google.com\> ' file<br>
i can get:
1:google.com
but way:
grep -nre '^\<go.gle.com\> ' file<br>
also :
1:google.com 2:go.gle.com
i want result " grep -nre '^\<go.gle.com\>
' file " is:
2:go.gle.com
not
1:google.com
how solve it?
ps: domain name in grep command "google.com" not fixed. maybe "goog.e.com" or ".oogle.com"
what you're looking (literal match) not possible grep
options because grep
treat matching pattern
regex , hence dot mean any character
.
you can use -f switch in grep
or use fgrep
fixed string match
result:
grep -nf 'go.gle.com ' infile
or:
fgrep -n 'go.gle.com ' infile
alternatively following awk command give output you're looking for:
awk 'index($1, "go.gle.com"){print nr ":" $0}' infile
or exact match:
awk '$1 == "go.gle.com"{print nr ":" $0}' infile
note i'm using awk's index function
or comparing equality ==
, hence matching string not considered regex.
Comments
Post a Comment