I have an input file that looks like this:
DATA-GROUP A
text 1
text 2
text 3
DATA-GROUP B
text 4
text 5
text 6
etc.
How can I extract each occurrence of the string "DATA-GROUP" and the lines beneath it until (but not including) the next occurrence to a new file? I would like to do this for all the occurrences so that I have multiple new files. For example, the first file would be:
DATA-GROUP A
text 1
text 2
text 3
The next would have DATA-GROUP B and so on. I tried the following:
numsets=($(grep -c "DATA-GROUP " input.txt))
for ((i=1;i<numsets+1;i++)); do
awk '/DATA-GROUP /&&++k=='"$i"',/DATA-GROUP /' input.txt > output"$i".txt
wait
done
but it didn't work.