Skip to content

Instantly share code, notes, and snippets.

@4ft35t
Last active December 30, 2019 09:24
Show Gist options
  • Save 4ft35t/4da88f9579d3c21071e911796a048682 to your computer and use it in GitHub Desktop.
Save 4ft35t/4da88f9579d3c21071e911796a048682 to your computer and use it in GitHub Desktop.
cat test.txt | sed  -n '/^start/,/^end/{/^start/,/i hate you/{/i hate you/p;};}'
i hate you 2
i hate you 4
i hate you 6
cat test.txt| awk '/start /{in_block=1; next} in_block && /i hate you/{t=$0; in_block=0; next} t && /end/{print t; t=""}'
i hate you 2
i hate you 4
i love you
i hate you 0
i hate you 0.1
end 0
movie starts
i hate you 1
start 1
i love you
i hate you 2
i hate you 3
end 1
end x
start 2
i love you
i hate you 4
i hate you 5
end 2
start 3
i love you
i hate you 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment