0

At the end of the third column there are three numbers that start with 1.0, how can I print all rows from the beginning until the first of these three numbers (it is in bold below) is found? is there a simple, one-liner solution with awk or sed?

-80.2743682     -8.6420053      0
-80.2740679     -8.6418526      0.0371169854015
-80.2737584     -8.641709       0.0747022394455
-80.2734489     -8.6415562      0.112728651431
-80.2731395     -8.6414126      0.150303954286
-80.27283       -8.6412689      0.187893918808
-80.2725297     -8.6411162      0.22501096103
-80.2722202     -8.6409635      0.263032506523
-80.2719108     -8.6408198      0.300612533441
-80.2716103     -8.6406581      0.33821233839
-80.27131       -8.6405053      0.375334461391
-80.2710095     -8.6403526      0.412471166086
-80.2707001     -8.6401999      0.450482911927
-80.2703906     -8.6400471      0.488509444666
-80.2700993     -8.6398853      0.52522713763
-80.2697989     -8.6397326      0.562354088058
-80.2694894     -8.6395709      0.600828217536
-80.2691981     -8.6394181      0.637071247595
-80.2688886     -8.6392473      0.676023425931
-80.2685882     -8.6390946      0.713150425596
-80.2682788     -8.6389509      0.750730603804
-80.2679783     -8.6387981      0.787872459485
-80.2676599     -8.6386635      0.825947927083
-80.2673686     -8.6385108      0.862185868818
-80.2670501     -8.6383762      0.900271491364
-80.2667406     -8.6382235      0.938293256103
-80.2664311     -8.6380798      0.975883478883
-80.2661217     -8.6379452      **1.01304928976**  <--- print until here
-80.2658214     -8.6378015      1.04972439283
-80.2655029     -8.6376578      1.08821462134

Any help is much appreciated.

oguz ismail
  • 1
  • 16
  • 47
  • 69
Gery
  • 8,390
  • 3
  • 22
  • 39
  • Please can you make the question explicit regarding whether the first line with >1 should or should not be included in the output. – alani May 28 '20 at 06:11
  • @alaniwi *until* implies the first line with >=1 is excluded – oguz ismail May 28 '20 at 06:14
  • 1
    @oguzismail I agree that that is probably the interpretation, but there is no harm in being explicit in order to be sure. – alani May 28 '20 at 06:22

3 Answers3

2

With awk it'd be:

awk '$3>=1{exit} 1' file
oguz ismail
  • 1
  • 16
  • 47
  • 69
  • I've asked for clarification of the question, regarding whether the final line should be included in the output or not. In this answer, it would not be included. This could be modified to `awk '$3>=1{print ; exit} 1' file` if it is required. – alani May 28 '20 at 06:14
  • 2
    @alaniwi In that case `awk '1; $3>=1{exit}' file` would be more idiomatic – oguz ismail May 28 '20 at 06:14
2

Could you please try following. Written and tested with shown samples only.

awk '1;$NF~/^1\.0/{exit}' Input_file 

Also in case your Input_file is having more than 3 fields then change above to:

awk '1;$3~/^1\.0/{exit}' Input_file


Sorry I am little confuse with description in case you need to print till 3rd occurrence of 1.0 then try following(though your shown bold lines shw you want to print till very first occurrence only but adding this in case anyone needs it).

awk '1;$NF~/^1\.0/ && ++count==3{exit}' Input_file 
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
1
sed -r '1,/.+ +.*+ +0.263/ p' -n < Input_file

this sed says:

  • don't print anything from Input_file
  • except for, starting with line 1
  • up to the line matching /.+ +.*+ +0.263/. Which means:
    • 1 or more characters followed by
    • 1 or more spaces followed by
    • 1 or more characters followed by
    • 1 or more spaces followed by
    • the number 0.263
  • print these lines

The regex can definitely be improved, by specifying start of line and spaces vs tabs. But the general idea is there.

Gerard Setho
  • 109
  • 2