输入:

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

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

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

我想要的输出:

v2.0.0

Added feature 3
Added feature 4

我尝试了this,但它得到的等于第一个(=),而的上一个等于(=),而我想获取的是,第一个等于(=)

最佳答案

这是awk中的一个:

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

Added feature 3
Added feature 4

精美打印:
$ 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

关于linux - 如何在文本/图案的前两个实例之间获取单词?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56147516/

10-15 00:18