+1 vote
in Programming Languages by (10.5k points)

The records in my file are tab-separated and one of the columns has value "1" and "0". I want to print all those records of the file that have "1" in that particular column. How can I print the whole record instead of just column value. e.g. If I use print $1, it will print the value in the first column. There are several columns in my file and I do not want to use print $1, print $2...

1 Answer

0 votes
by (13.5k points)

Have you tried "print $0"? It should print the whole record.

Try the following if your file is not zipped:

awk 'BEGIN{FS="\t"}{if ($column_num=="1") print $0}' filename

Try the following if your file is zipped:

zcat filename | awk 'BEGIN{FS="\t"}{if ($column_num=="1") print $0}'

...