1

There are some questions alike in this site, but mine is a bit different.

I have a 30 GB text file, and I need to split it into smaller files according to the different record values.

For example;

   NAME       DATE      AMOUNT  
    AA      02.03.2014  768,30
    AA      03.03.2014  234,15
    BB      12.01.2014  238,00
    BB      15.09.2014  567,00
    BB      06.12.2014  323,00
    CC      08.02.2015  456,00
    CC      09.02.2015  213,00

into ---->

AA.TXT

   NAME       DATE      AMOUNT  
    AA      02.03.2014  768,30
    AA      03.03.2014  234,15

BB.TXT

   NAME      DATE        AMOUNT 
    BB       12.01.2014  238,00
    BB       15.09.2014  567,00
    BB       06.12.2014  323,00

CC.TXT

   NAME     DATE         AMOUNT
   CC      08.02.2015    456,00
   CC      09.02.2015    213,00

Here I've found a clue, but I barely know Powershell scripting, so I couldn't figure out a way to split files according to the NAME value.

In the answer which I've cited above, it seeks for a bracket [ , what I seek is a different value from the one above in the NAME column.

AND;

Smaller files in .txt formats will do the job BUT the following is appreciated:

--If row count is < 1.000.000 , then extract the records into a .xls (or .xlsx) file.

Any solutions in any other languages are also welcomed.

Thanks.

1
  • Did the python solution work?
    – user236012
    Feb 11, 2015 at 9:02

1 Answer 1

2

Python:

cpath="C:/Path/to/File"
infile=cpath+"/data.txt"

with open(infile) as f:
for line in f:
         content = line.split()

         outfile = cpath + "/" + content[0] + ".txt"

         with open(outfile,'a') as f2: 
              f2.write(line)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .