I have searched for a similar topic here but most questions included single-character delimiter.
I have this sample of text:
Some text here,
continuing on next lineDELIMITERSecond chunk of text
which may as well continue on next lineDELIMITERFinal chunk
And the desired output is a list (extracted=()) which contains:
Some text here,
continuing on next lineSecond chunk of text
which may as well continue on next lineFinal chunkAs could be seen from the sample, "DELIMITER" is used as a splitting delimiter.
I have tried numerous samples on SO incl awk, replacing etc.
In case you don't want to change default RS value then could you please try following.
awk '{gsub("DELIMITER",ORS)} 1' Input_file
With AWK please try the following:
awk -v RS='^$' -v FS='DELIMITER' '{
n = split($0, extracted)
for (i=1; i<=n; i++) {
print i". "extracted[i]
}
}' sample.txt
which yields:
1. Some text here,
continuing on next line
2. Second chunk of text
which may as well continue on next line
3. Final chunk
If you require to transfer the awk array to bash array, further step will be needed depending on the succeeding process on the array.
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