How can I get words between the first two instance of text/pattern?
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
Here is another one in GNU sed:
$ sed -n '/^=\+$/,//{//!p;b};q' file
v2.0.0
Added feature 3
Added feature 4
/^=\+$/,//
is a shorthand for/^=\+$/,/^=\+$/
, it selects the lines between two lines consisting of equal signs inclusively, and the commands between following curly braces are executed for these lines,//!p
is a shorthand for/^=\+$/!p
, it means if incoming line is not one of those which consist of only=
s, print it,b
means go to the end of cycle (i.e passq
),q
is for exitting sed after printing selected lines.
The following version will work with all POSIX-compliant seds but it looks 2x more cryptic:
sed -n -e '/^=\{1,\}$/,//{//!p;b' -e '}' -e 'q' file
Note that these are not gonna work if there are two consequent all =
lines in the input.
Could you please try following too.
awk '/^=/{count++;next} count>=2{exit} {print}' Input_file