Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get words between the first two instance of text/pattern?

Input:

===================================
v2.0.0

Added feature 3
Added feature 4
===================================
v1.0.0

Added feature 1
Added feature 2
===================================

Output that I want:

v2.0.0

Added feature 3
Added feature 4

I tried this but it gets the first equals (=) and the LAST equals (=) while I want to get is the FIRST TWO equals (=)

like image 731
Tenten Ponce Avatar asked May 15 '19 10:05

Tenten Ponce


2 Answers

Here is one in awk:

$ awk '/^=+$/{f=!f;if(f==1)next;else if(f==0)exit}f' file
v2.0.0

Added feature 3
Added feature 4

In pretty print:

$ awk '/^=+$/ {     # at ===...
    f=!f            # flag state is flipped
    if(f==1)        # if its one (first ===...)
        next        # next record
    else if(f==0)   # if zero (second ===...)
        exit        # nothing more to do yeah
}
f' file             # print
like image 69
James Brown Avatar answered Nov 15 '22 00:11

James Brown


Could you please try following too.

awk '/^=/{count++;next} count>=2{exit} {print}'  Input_file
like image 3
RavinderSingh13 Avatar answered Nov 14 '22 23:11

RavinderSingh13