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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk to display lines that contain a period only in the first column
# 1  
Old 10-09-2012
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.

Code:
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...

Code:
awk '$1 ~ "."' file

Thanks in advance
# 2  
Old 10-09-2012
You need to escape the . since is a special character : \.
Code:
awk '$1 ~ /\./' file

# 3  
Old 10-09-2012
This will print the line if column1 contains a period(.):
Code:
awk '$1~/\./ {print $0}'

This User Gave Thanks to spacebar For This Post:
# 4  
Old 10-09-2012
Quote:
Originally Posted by spacebar
This will print the line if column1 contains a period(.):
Code:
awk '$1~/\./ {print $0}'

Man... I spent hours trying to figure this out. Thanks for the help Smilie
# 5  
Old 10-09-2012
You were close in your piece of code...

use
Code:
awk '$1 ~ "\\."' file

This User Gave Thanks to scottaazz For This Post:
# 6  
Old 10-09-2012
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.
Code:
awk 'index($1, ".")' file

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 7  
Old 10-09-2012
All of those solutions worked. Thanks again guys.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk copy first column in new lines

Hi all i have table like this input001_1_174 j 474536 482492 mo001_1_175 j 960192 966656 .ire 966656 984416 .uf/i want copy number of first line to other line... (10 Replies)
Discussion started by: alii
10 Replies

2. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

3. Shell Programming and Scripting

awk to filter out lines containing unique values in a specified column

Hi, I have multiple files that each contain four columns of strings: File1: Code: 123 abc gfh 273 456 ddff jfh 837 789 ghi u4u 395 File2: Code: 123 abc dd fu 456 def 457 nd 891 384 djh 783 I want to compare the strings in Column 1 of File 1 with each other file and Print in... (3 Replies)
Discussion started by: owwow14
3 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. UNIX for Dummies Questions & Answers

awk solution to duplicate lines based on column

Hi experts, I have a tab-delimited file with one column containing values separated by a comma. I wish to duplicate the entire line for every value in that comma-delimited field. For example: $cat file 4444 4444 4444 4444 9990 2222,7777 6666 2222 ... (3 Replies)
Discussion started by: torchij
3 Replies

6. Shell Programming and Scripting

Display all the matches lines in one line using awk

Please can you let me know how to print all the matching lines from a file in one single line using awk. Thanks I have the following data in the input file data1 voice2 voice1 speech1 data2 data3 ... ... voice4 speech2 data4 and the output should be as follows data1 data2... (4 Replies)
Discussion started by: Sudhakar333
4 Replies

7. Shell Programming and Scripting

Find duplicates in column 1 and merge their lines (awk?)

Hi, I have a file (sorted by sort) with 8 tab delimited columns. The first column contains duplicated fields and I need to merge all these identical lines. My input file: comp100002 aaa bbb ccc ddd eee fff ggg comp100003 aba aba aba aba aba aba aba comp100003 fff fff fff fff fff fff fff... (5 Replies)
Discussion started by: falcox
5 Replies

8. Shell Programming and Scripting

awk print non matching lines based on column

My item was not answered on previous thread as code given did not work I wanted to print records from file2 where comparing column 1 and 16 for both files find rows where column 16 in file 1 does not match column 16 in file 2 Here was CODE give to issue ~/unix.com$ cat f1... (0 Replies)
Discussion started by: sigh2010
0 Replies

9. Shell Programming and Scripting

Searching the lines within a range of time period in a text file

Dear All, Please advice me, I have a text file with one field date and time like below given. I need to find out the lines whchi content the time stamp between Wed May 26 11:03:11 2010 and Wed May 26 11:03:52 2010 both can be included, using awk command which could be an interactive so that I... (6 Replies)
Discussion started by: chinmayadalai
6 Replies

10. UNIX for Dummies Questions & Answers

remove lines in text starting with . (period)

how can i remove lines from a text file starting with . (a period) (11 Replies)
Discussion started by: Movomito
11 Replies
Login or Register to Ask a Question