I have text files which I'd like to divide up into different files based on arbitrary "tags" I put at the start of various lines.
Example text file:
I CELEBRATE myself, and sing myself,
And what I assume you shall assume,
For every atom belonging to me as good belongs to you.
#here I loafe and invite my soul,
#here I lean and loafe at my ease observing a spear of summer grass.
#there My tongue, every atom of my blood, form'd from this soil, this air,
#there Born here of parents born here from parents the same, and their parents the same,
#here I, now thirty-seven years old in perfect health begin,
#here Hoping to cease not till death.
In this example I'd like to remove every line beginning with #here and append it onto a file called here.txt, every line beginning with #there into a file called there.txt, and leave every untagged line in the original file. (Ideally removing the #here #there tags in the process.)
I think this solution using awk might be helpful, but I am such a Unix noob that I don't know how to adapt this to my problem: How to split a file by using keyword boundaries
Any suggestions on how to proceed?
PS: I'm using the command line on OS X.