Text Processing – Extract Text Between Two Specific Lines

text processing

How can I get the part of the output of a command between two specific lines? A dummy example:

Command:

git for-each-ref --sort='*authordate' --format='%(tag)' refs/tags | grep -v '^$'

Output:

0.1.0
0.2.0
1.0.0
1.0.1
1.0.2
1.1.0
1.2.0
1.2.1
1.3.0
1.4.0
1.4.1

I want to get the part of this output, between two specific lines (not based on line number, based on content):

0.1.0
0.2.0
1.0.0
1.0.1
1.0.2

Best Answer

You can pipe output to awk:

$ ... | awk '/0\.1\.0/,/1\.0\.2/'
0.1.0
0.2.0
1.0.0
1.0.1
1.0.2
Related Question