How to split text between separator into multiple files?

Simple awk command:

awk 'NR%2==0{ print > "File "++i }' RS='"' file

RS defines " as record separator and NR is the record number. If the record number was modulo of 2 (because we have another first " for records), then print the current record $0 into a File #.


If the opening quote is always at the beginning of the line, csplit will work just fine like this:

bash$ csplit /tmp/data '/^"/'

That produces files called xx00, etc. Note, your example removes the quotation marks and this doesn't. You'd need a command line sed to do that:

bash$ for file in xx* ; do { sed 's/^"//;s/"$//;' ${file} >x${file}; } ; done

With GNU awk

awk -v RS='"[[:space:]]*"' '
{sub(/^"|"[[:space:]]*$/, "");print > "output." ++n; close("output." n)}' file.txt