How can I get text using grep command txt that seats between two strings?
for example:
<--string 1-->
the text i need
<--string 2-->
the "the text i need" between the two tags is dynamic, therefor i need a command that will output text from "<--string 1-->" to "<--string 2-->"
This might work for you:
grep -A2 "<--string 1-->" file | grep -v "<--string 1-->\|<--string 2-->"
or
grep -A1 "<--string 1-->" file | grep -v "<--string 1-->"
or in a single process:
sed '/<--string 1-->/,/<--string 2-->/!d;//d' file
or:
awk '/<--string 2-->/{p=0};p;/<--string 1-->/{p=1}' file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With