4

I have an input table, partially:

TCTTTTAAAGCCTCCTCAACTGTTTTAGGG  1       0
CACAACTGAAAAGTACAATGTGTTTGCTTC  1       0
CACCATATTTATTTAAAGGAGCATCTAAAT  1       3
ACGAGAAAAAAAAAAGGGGTGACCCCCTGG  3       0
CAAAATATTAATTCTTTACTATGAAACTTA  1       0
TTCTATTTTGTCGTGGTTAGCAACCATCAC  6       5
TAATAATAAAATAATGAAAAAGAAAAATCA  1       0
AAAGCATTTGAAGGTGACAAAAGGGAAAGT  20      7
TGCTAAGGAAGAATCATGGAAGAGTGTTTT  0       1
CTCCCTTCCTCGCAAACATGCTTGCCCAGG  0       1
AATAAAAATCAAATTTAGTGACGGGTTGAG  130     4
AGAACGAAGCTGATATAAAGACATCAAAGA  1       0
TGCCCCTAATGCAGCATCTCTCTCTCCCTC  1       0
CCACAAAATAATTACATGGCAAACACGAGT  1       0

I want to print all the lines with column 3 >= 120 and column 2 >= 420

I have got two different results by using and not using "" around the number.

(A) awk '$3>=120 && $2>=420 {print $0}'

(B) awk '$3>="120" && $2>="420" {print $0}'

Result of (A) partially, which seems to be what I want :

GTGTCATTTCATGCCTCATTCATCCTCATT  1375    439
TGAATTCTATTACTTGATTGACATTGACAG  541     301
TCTTTGGCGGTTGTTAAAGAATTTTCTGAT  823     203
TCTACACCTCAATATGCAAAACATTACATC  535     165
TTCAACAAATTAATTAAAATTGAATTAAAC  3010    627
GATATGTAAAAAAAATTATATTATATGAAT  609     173

Result of (B) partially, is not what I want :

TAATAATAATAATAAAAGAAGAAGAAAAGA  5       2
TATCTGAGCTATCAACTCAATTCATCGTCG  5       4
TTAATGATAAATTTATCTTAAAAGTTTAAC  62      23
TTCAACCCCCTCTCCTGGTGTGTGCCCTAG  45      7
TCCAAAGCCTTTAATGTGTACCGCGTGAAA  6       5
GGCAATGGGATACTCCTGTATGTTATTCTA  6       3

The question comes to my mind : How does the quotation mark (") in number selection made the difference?

Thank you very much.

7

Quotation marks force a comparison on the string representation of your numbers. Alphabetically, "42" comes after "120" (you then have "42" > "120"); numerically it doesn't (you then have 42 < 120).

3

Perform the comparisons without the quotes, or they will be string comparisons that are performed lexicographically.

The tiny awk script may be further reduced in size by allowing the default action to be performed. The default action for a conditional test that does not have a {...} block is to print the current input line:

awk '$2>=420 && $3>=120' data.in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.