Hi
I have a large text file and I want to split its content into multiple flies.
this large file contains several blocks of codes separated by a comment line for each block.
this comment line represents a directory path
So, when separate these blocks each into a separate file, This output file should be in the same name and directory of its block comment.
---------- Post updated at 02:39 AM ---------- Previous update was at 12:33 AM ----------
I manage to make it work , only when I remove the // from the first line of the large file and keep the subsequent //home/xxxx directory path entries
However, when a block does contain another comment (it is also // but not the //home/xxx directory path), it will cut that file and wont create the blocked file fully. i.e it will crate the block file but not complete!
What I need is to create separate files from the large file , while each block is identified by the full path of the directory:
//home/user/app1/lib/note1.txt
Here is an example of the original file (I will call it x1) that I want to split it into multiple text files (t1.txt, t2.txt and t3.txt) in the directory /home/turki/Downloads/widd (which is already exist)
this is the content of the original file x1
/home/turki/Downloads/widd/t1.txt
t1 file starts here
/****************************************************************************
WISO PROJECT Version : 1.5 //some comment here
end t1
//home/turki/Downloads/widd/t2.txt
t2 file starts here
/****************************************************************************
WConsole Class
end t2
//home/turki/Downloads/widd/t3.txt
t3 file starts here
/****************************************************************************
WInstance Class
end t3
When I use the command:
awk -v RS="//" '{ print > "//"$1 }' x1
it does split the content of the x1 file into 3 files t1.txt, t2.txt and t3.txt each in its specified location (inside the "widd" directory)
However, the problem is that if the section of the file contains a comment (like in t1.txt section //some comment here) the split of that file stops there and does not show the whole content of t1 section in the t1.txt file. But I have no problem with t2 and t3 as the content for t2 and t3 does the perfect job of copying the whole content to their appropriate txt files.
How can I split the content of the t1 section EVEN with the comment inside it to the new t1.txt file?