awk to output lines less than number

I am trying to output all lines in a file where $7 is less than 30. The below code does create a result file, but with all lines in the original file. The original file is tab deliminated is that the problem? Thank you :).

 awk 'BEGIN{FS=OFS=","} $7 < 30 {print}' file.txt > result.txt 

file.txt

chr1    40539722    40539865    chr1:40539722-40539865    PPT1    1    159
chr1    40539722    40539865    chr1:40539722-40539865    PPT1    2    161
chr1    40539722    40539865    chr1:40539722-40539865    PPT1    3    161
chr1    40539722    40539865    chr1:40539722-40539865    PPT1    3    28 

Desired result.txt

 chr1    40539722    40539865    chr1:40539722-40539865    PPT1    3    28 

---------- Post updated at 12:12 PM ---------- Previous update was at 11:59 AM ----------

It was the FS=OFS="'," .... should be OFS="/t" , guess I need to pay more attention. FS is Field seperator and OFS is Output Field Seperator, right? Thank you :).

Yes, if input file is tab separated, then you have to set FS - input field separator to \t not OFS - output field separator.

awk -F'\t' '$7+0 < 30' file
1 Like

You write "The original file is tab deliminated" but set FS to ",". That doesn't fly. As <TAB> is one of the default field separators,

awk ' $7 < 30' file
chr1    40539722    40539865    chr1:40539722-40539865    PPT1    3    28

will do.

1 Like

Thank you :slight_smile: