5

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
8

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
  • Yes, that's exactly what I need, works as expected. Thanks a lot :) – Ahmet Sezgin Duran Aug 22 '14 at 12:25
6

you can pipe it to sed:

.... | sed -n "/0.1.0/,/1.0.2/p" YourFile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.