huangzihyun
Programmer
I have pattern file like below
123456
234567
789012
345678
456789
...
...
...
and another data_file repeat as below(about 500 lines)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
...
...
...
...
...
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
now I need to split data file from #aaaaaaaaaa to ddddddddddd as a block, one block for one split file,
and every split file's filename must sequentially read from pattern file.
such as:
123456 (filename1)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
234567 (filename2)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
789012 (filename3)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
345678 (filename4)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
(filename5)
(filename6)
How to code this?
there is a code
gawk -v n=1 '/ddddddddddd/{close("splitfile"n);n++;next} {print > "splitfile"n}' data_file
could easyily split file,
but how to put pattern into close() as filename?
Thanks
123456
234567
789012
345678
456789
...
...
...
and another data_file repeat as below(about 500 lines)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
...
...
...
...
...
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
now I need to split data file from #aaaaaaaaaa to ddddddddddd as a block, one block for one split file,
and every split file's filename must sequentially read from pattern file.
such as:
123456 (filename1)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
234567 (filename2)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
789012 (filename3)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
345678 (filename4)
#aaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
(filename5)
(filename6)
How to code this?
there is a code
gawk -v n=1 '/ddddddddddd/{close("splitfile"n);n++;next} {print > "splitfile"n}' data_file
could easyily split file,
but how to put pattern into close() as filename?
Thanks