AWK

Soldato
Joined
24 Nov 2002
Posts
16,379
Location
38.744281°N 104.846806°W
I tried to help someone with something quick this morning to save writing a program:

awk -F\t, '{ if ($1 == "10") print $0 }' file.text

That is, output lines that have the first column as "10" But it didn't work - it's been a ahilwe.

I actually want to check two columns, but wanted this to work first.

Any ideas?
 
Last edited:
1) I assume \t works for a tab delimiter

2) You're missing a closing bracket after "10"

Otherwise it looks OK to me. If it still doesn't work post any errors it's returning and I'll have another look
 
Missing quotes around the field-separator.

Code:
~/tmp$ cat file.text
1       ,hello  1
2       ,hello  2
10      ,hello  3
3       ,hello  4
10      ,hello  5
10      ,hello  6
7       ,hello  7

Code:
~/tmp$ awk -F\t, '{ if ($1 == "10") print $0 }' file.text
~/tmp$ awk -F"\t," '{ if ($1 == "10") print $0 }' file.text
10      ,hello  3
10      ,hello  5
10      ,hello  6
~/tmp$
 
Back
Top Bottom