I have a text , that I want to print what ever between 2 words in that text showing only the first occurrence and disabling greediness if exist for example lets say that I have this text
word1 XXXX
TTTT
YYYY
ZZZZ
GGGG word2 JJJJJJJ word2
ads
word2
adasdas
word1
asadadsasd
word2
what I want is
XXXX
TTTT
YYYY
ZZZZ
GGGG
thanks
So I have a bit of a hack here. But it works.
Test file:
Output:
Sed command:
sed -n '/word1/,$p' file | sed -n '1,/word2/p'The first sed command matches all the lines from
word1all the way to the end of the file and then we pipe it into the second sed command which matches all the lines from the beginning of the file (which we just piped into it) all the way untilword2is matched. Its tricky but it works.