user2532296 user2532296 - 2 months ago 5
Python Question

removing 0.0 from second column in file

I have a file log.txt that has the format shown below.

log.txt



280,249.999441
140,0.0
140,0.0
84917,182.59465
140,0.0
72161,185.615882
304,249.998589
280,240.184619


I want to remove all the entries that has 0.0 in the second column.

expected output:



280,249.999441
84917,182.59465
72161,185.615882
304,249.998589
280,240.184619


I want the simplest and fastest way to do the above. I am open to all tools.

Thanks

Answer

You can use awk:

awk -F, '$2 != "0.0"' log.txt

280,249.999441
84917,182.59465
72161,185.615882
304,249.998589
280,240.184619

-F, sets input field separator as comma and $2 != "0.0" checks if 2nd column is not 0.0.

Comments