Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWK code to remove rows integer or 0.5 decimal

I have a list of coordinates with fixed Lon and vary Lat like this:

75.5    36.5    37.4290504456
75.5    36.4    52.4753456116
75.5    36.3    66.4775466919
75.5    36.2    84.0023193359
75.5    36.1    111.997085571
75.5    36  172.343933105
75.5    35.9    111.806427002
75.5    35.8    83.5655899048
75.5    35.7    65.6402206421
75.5    35.6    50.8337936401
75.5    35.5    33.7828178406

But I would like to remove all rows where lat are integer or a number with 0.5 to have something like this:

75.5    36.4    52.4753456116
75.5    36.3    66.4775466919
75.5    36.2    84.0023193359
75.5    36.1    111.997085571
75.5    35.9    111.806427002
75.5    35.8    83.5655899048
75.5    35.7    65.6402206421
75.5    35.6    50.8337936401

(I removed 36.5, 36 and 35.5)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I do this using awk?

>Solution :

Since it’s integers or .5s (special case), you can use $2 modulo 0.5:

$ awk '$2%0.5' file

75.5    36.4    52.4753456116
75.5    36.3    66.4775466919
75.5    36.2    84.0023193359
75.5    36.1    111.997085571
75.5    35.9    111.806427002
75.5    35.8    83.5655899048
75.5    35.7    65.6402206421
75.5    35.6    50.8337936401
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading