I have a very large text file, test.txt
, in the following format:
(Same specific character or word like '^' or '*') Title 1 (end-of-line)
Text 1 (with paragraphs markers, end-of-line markers spaces, all kinds of stuff)
(Same specific character or word like '^' or '*') Title 2 (end-of-line)
Text 2 (with paragraphs markers, spaces, all kinds of stuff)
(Same specific character or word like '^' or '*') Title 3 (end-of-line)
Text 3 (with paragraphs markers, spaces, all kinds of stuff)
...
I'd like to make two arrays, one corresponding to the strings { "Title 1", "Title 2", "Title 3", ...}
, and the other corresponding to the strings { "Text 1", "Text 2", "Text 3", ...}
.
Is there a simple one-liner to do this?
Here's a specific test example.
Here each line starting with ^
should be a "Title"
(of which there are three), and the material between the ^
corresponds to "Text"
(of which there are three sections). Notice that ^
only appears as the first character in the "Title"
string, and that each title is finished with an end-of-line, and finally that each "Text"
section can consist of multiple lines of strings.