Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I have a text file in following format. Separate blocks of data are there, they are separated by a blank line. There are NO blanks in between data rows. First row of each data clock is a fixed one.
Game Date Process CDR Sell Reck
23 Test rts 123TST rt 45
34 No riverse 123 only na na
. . . . . .
155 na govt frame no sk
Game Date Save
12 no yes - do
13 Yes exact
. . .
16 do perfectI need to split these data blocks in to different text files.
My output file 1 :
Game Date Process CDR Sell Reck
23 Test rts 123TST rt 45
34 No riverse 123 only na na
. . . . . .
155 na govt frame no skMy output File 2:
Game Date Save
12 no yes - do
13 Yes exact
. . .
16 do perfectAppreciate your assistance to do this process using a UNIX script.
Thanks.

Assuming the "blank lines" you described is fixed, eg "\n\n\n", and also your file is not very big, using Python:
>>> f = open("inputfile.txt").read()
>>> all = f.split("\n\n\n")
>>> i = 1 #counter to name your output files
>>> for items in all:
............open(str(i) + ".txt","w").write(items)
............i = i + 1
...
>>>the output files will be 1.txt , 2.txt...etc

I think you want to use the csplit command which splits a file based on regular expressions. Take a look at these links:
http://www.computing.net/unix/wwwboard/forum/7415.html
http://www.computing.net/unix/wwwboard/forum/7134.html

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |