-2

I have this text file:

echo "Start 2A25.20090401.64809.7.HDF 6420 6751" 
echo "dimensions 9249 49"  
echo "New Cell"   
grep "6449,34" out.2A25.20090401.64809.7.HDF.txt.text = 19.01  11.13  72.53 291
echo "New Cell"   
grep "6466,35" out.2A25.20090401.64809.7.HDF.txt.text = 18.97  10.80  73.07 237
echo "New Cell"   
grep "6483,08" out.2A25.20090401.64809.7.HDF.txt.text = 19.75   9.43  72.89 237
echo "New Cell"   
grep "6524,14" out.2A25.20090401.64809.7.HDF.txt.text = 22.95   8.77  74.29 291
echo "New Cell"   
grep "6529,38" out.2A25.20090401.64809.7.HDF.txt.text = 21.62   9.54  75.06 237
echo "New Cell"   
grep "6542,06" out.2A25.20090401.64809.7.HDF.txt.text = 20.09   8.07  74.61 170
grep "6542,07" out.2A25.20090401.64809.7.HDF.txt.text = 32.25   8.11  74.64 210
grep "6543,06" out.2A25.20090401.64809.7.HDF.txt.text = 33.28   8.05  74.64 210
grep "6543,07" out.2A25.20090401.64809.7.HDF.txt.text = 43.38   8.09  74.67 210
grep "6543,08" out.2A25.20090401.64809.7.HDF.txt.text = 24.22   8.13  74.70 210
grep "6544,06" out.2A25.20090401.64809.7.HDF.txt.text = 35.81   8.03  74.67 210
grep "6544,07" out.2A25.20090401.64809.7.HDF.txt.text = 41.58   8.07  74.70 200
grep "6545,06" out.2A25.20090401.64809.7.HDF.txt.text = 36.3   8.01  74.70 120
grep "6545,07" out.2A25.20090401.64809.7.HDF.txt.text = 31.57   8.05  74.73 210
grep "6546,06" out.2A25.20090401.64809.7.HDF.txt.text = 28.49   7.99  74.73 292
echo "New Cell"   
grep "6552,03" out.2A25.20090401.64809.7.HDF.txt.text = 18.92   7.74  74.83 237
echo "New Cell"   
grep "6560,10" out.2A25.20090401.64809.7.HDF.txt.text = 23.2   7.83  75.26 291
echo "New Cell"   
grep "6562,21" out.2A25.20090401.64809.7.HDF.txt.text = 26.74   8.19  75.61 210
grep "6563,20" out.2A25.20090401.64809.7.HDF.txt.text = 26.35   8.13  75.62 210
grep "6563,21" out.2A25.20090401.64809.7.HDF.txt.text = 42.51   8.17  75.64 200
grep "6563,22" out.2A25.20090401.64809.7.HDF.txt.text = 25.82   8.20  75.67 210
grep "6564,20" out.2A25.20090401.64809.7.HDF.txt.text = 23.08   8.11  75.65 272
grep "6564,21" out.2A25.20090401.64809.7.HDF.txt.text = 46.55   8.15  75.67 200
grep "6564,22" out.2A25.20090401.64809.7.HDF.txt.text = 36.89   8.18  75.70 200
grep "6565,21" out.2A25.20090401.64809.7.HDF.txt.text = 31.61   8.12  75.70 200
grep "6565,22" out.2A25.20090401.64809.7.HDF.txt.text = 28.85   8.16  75.73 120
echo "New Cell"   
                                                                                                                             23,1          Top

I want to delete the ROWS in which Column 8 (Number 200, 210, 120) is less than 200, But the New Cell has to be retained. I have tried awk like this:

awk '{if ($8 >= 200) print $0}' CSWoSpix.apr2009.sh >OUT1

But it does not retain the echo "New Cell " lines.

  • 1
    please format your question, see unix.stackexchange.com/editing-help and add complete expected output for given sample input for clarity – Sundeep Nov 27 '17 at 15:55
  • echo "Start 2A25.20090401.64809.7.HDF 6420 6751" echo "dimensions 9249 49" echo "New Cell" grep "6542,07" out.2A25.20090401.64809.7.HDF.txt.text = 32.25 8.11 74.64 210 grep "6543,06" out.2A25.20090401.64809.7.HDF.txt.text = 33.28 8.05 74.64 210 grep "6543,07" out.2A25.20090401.64809.7.HDF.txt.text = 43.38 8.09 74.67 210 grep "6543,08" out.2A25.20090401.64809.7.HDF.txt.text = 24.22 8.13 74.70 210 grep "6544,06" out.2A25.20090401.64809.7.HDF.txt.text = 35.81 8.03 74.67 210 is the expected O/p – geet Nov 27 '17 at 16:10
1

To print a line if it either has field 8 greater than 200 or if it contains the phrase New Cell, try:

awk '{if ($8 >= 200 || /New Cell/) print $0}' filename

Because print is awk's default action, the above can be simplified to:

awk '$8 >= 200 || /New Cell/' filename

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.