split file content into specific folders

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.

an example of the large file content is:

//home/user/app1/lib/note1.txt
xyz
xyz
zylij
//home/user/app1/core/note2.txt
xyz
xyz
zylij

The result will be 2 files:
note1.txt file is created in the path //home/user/app1/lib

and

note2.txt file is created in the path //home/user/app1/core

and so on

Kindly, can you help in writing such a script

Thank you

awk -v RS="//" '{ print > "//"$1 }' inputfile

Use nawk on solaris.

Didn't work

awk: cannot open "//" for output (Is a directory)

---------- 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

rather than just //

I hope I am making myself understandable

thank you

I'm afraid you aren't.

What things did you change to make it work?

What did it then do?

Would this solve the splitting of the content into multiple files?

All files in same directory:

awk 'BEGIN{FS="/"}{if($NF ~ /note.*txt/) y=$NF; if($NF !~ "txt") print $0 > y }' infile

or

All files in given directory

awk 'BEGIN{FS="//"}{if($NF ~ /note.*txt/) y=$NF; if($NF !~ "txt") print $0 > y }' infile

Note: Posix awk will only allow RS to consist of a single character.

still not working :frowning:

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?

Thank you,

Hi guys,

any help?