How do you split a filebase on a token?
Let's say you have a file containing texts (1 to N), separated by $. How to cut a file so that the end result is N files?
text1 with newlines $
text2 $, etc. $
textN
I am thinking something with awk or sed, but is there any unix application available that already does such a task?
source to share
Maybe a split -p
pattern?
Hmm. This may not be exactly what you want. It doesn't break the line, it only starts a new file when it sees the template. And it seems to be only supported on BSD related systems.
You can use something like:
awk 'BEGIN {RS = "$"} { ... }'
edit: You can find some inspiration for the part { ... }
here:
http://www.gnu.org/manual/gawk/html_node/Split-Program.html
edit: Thanks to the comment from dmckee, but csplit
also copies the entire line where the template occurs.
source to share