I got multiple text files that resemble dictionary entries. One such text file can look like this:
MEANING:
content1
content2
IDIOM:
content3
content4
Another can be like this:
MEANING:
content1
content2
SYNONYMS:
content2
content3
content5
Now my wish is to extract the content of "MEANING" section using one sed command line. Here is my idea for the first text file, where "IDIOM" comes after the "MEANING" part:
cat dicentry1.txt | sed -e 's/MEANING\(.*\)IDIOM/\1/')
Thing is, that the output is:
MEANING:
content1
content2
IDIOM:
content3
However, this doesn't even work yet, even though user "Brian Campbell" suggested exact same line with just other values in this thread: How to use sed/grep to extract text between two words?
My second problem would be to do this with the second file, where "SYNONYMS" comes after the "MEANING" part. Technically, I could do just the same as above but with "/SYNONYMS" instead of "/IDIOM". However, wouldn't be something like this possible?
DISCLAIMER: It is in idea and the syntax may be completely wrong, I apologize for that in advance T.T
cat anydicentry.txt | sed -e 's/MEANING\(.*\)\(IDIOM|SYNONYM\)/\1/')
What this line is suppose to do is to copy everything after "MEANING" to the point where either "IDIOM" or "SYNONYMS" appears. However, I still can't get this working and I have no idea how I could implement it.
I hope that you understand my two issues I am having.
Thanks in advance, guys!