Awk to display lines that contain a period only in the first column

I've been trying to figure this out for quite a bit... I'm trying to check the first column for a period and only display the line if it contains a period. Below is a sample of the data i'm working with.

www.homestorest	7200	IN	CNAME	www.homestorest.fishing.net.shopit.net.
homestorestfeeds	7200	IN	CNAME	homestorestfeeds.fishing.net.mana.net.
homestoreststore	7200	IN	A	10.10.10.10
sprint.qa.homestoreststore	7200	IN	A	5.5.5.5
asdf.homestyle	7200	IN	CNAME	master.fishing.mom.net
mip	7200	IN	CNAME	xip-geo.xplat.fishing.mana.net.
anoc-ir	7200	IN	CNAME	cmts.g

I've tried the following but it's checking against both columns...

awk '$1 ~ "."' file

Thanks in advance

You need to escape the . since is a special character : \.

awk '$1 ~ /\./' file

This will print the line if column1 contains a period(.):

awk '$1~/\./ {print $0}'
1 Like

Man... I spent hours trying to figure this out. Thanks for the help :slight_smile:

You were close in your piece of code...

use

awk '$1 ~ "\\."' file 
1 Like

Or better yet, don't use regular expressions. A regular expression is only needed when matching an indeterminate string. In this case, you know the string, a single dot, so index() is sufficient.

awk 'index($1, ".")' file

Regards,
Alister

1 Like

All of those solutions worked. Thanks again guys.