-1

I have a datafile with 5 columns and N numbers of rows, I want delete every rows that have value equal to zero (0.00) in the first column. For example, this is the original file

-1.3  -2.00  -3.00  4.00  9.00 
0.10  -0.20  -0.80  4.50  1.70
0.00  -3.40  -6.80  5.60  9.30
-0.4  -3.20  -4.70  0.80  -0.9
1.03  -2.00  -3.00  4.00  9.00 
0.00  -6.80  -9.30  3.40  5.60
0.00  -4.70  -0.80  8.90  -0.3

And this is the file that i want to get

-1.3  -2.00  -3.00  4.00  9.00 
0.10  -0.20  -0.80  4.50  1.70
-0.4  -3.20  -4.70  0.80  -0.9
1.03  -2.00  -3.00  4.00  9.00 

Please help me

James Brown
  • 36,089
  • 7
  • 43
  • 59
  • https://stackoverflow.com/questions/5410757/how-to-delete-from-a-text-file-all-lines-that-contain-a-specific-string – James Brown Jul 06 '22 at 11:28

1 Answers1

1

I would use GNU AWK for this task following way, let file.txt content be

-1.3  -2.00  -3.00  4.00  9.00 
0.10  -0.20  -0.80  4.50  1.70
0.00  -3.40  -6.80  5.60  9.30
-0.4  -3.20  -4.70  0.80  -0.9
1.03  -2.00  -3.00  4.00  9.00 
0.00  -6.80  -9.30  3.40  5.60
0.00  -4.70  -0.80  8.90  -0.3

then

awk '!($1=="0.00")' file.txt

gives output

-1.3  -2.00  -3.00  4.00  9.00 
0.10  -0.20  -0.80  4.50  1.70
-0.4  -3.20  -4.70  0.80  -0.9
1.03  -2.00  -3.00  4.00  9.00 

Explanation: single condition just describe lines which you want: not (!) first field ($1) is (==) string 0.00 ("0.00")

(tested in gawk 4.2.1)

Daweo
  • 31,313
  • 3
  • 12
  • 25