473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.txt file to excel .csv

Hello,

I have some very large(several Mb) text files I am trying to process and parse using a Python script (novice python user). I am using the eclipse IDE and version 3 of python if that makes a difference.

I am trying to also make use of the csv module in python.

the .txt file has the following format for data:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 09:04:11
  3. <break>0M!00021<CR><LF>
  4. 0<CR><LF>
  5. 0D0!0+32044+31681<CR><LF>
  6.  
  7. 09:04:16
  8. <break>0M!00021<CR><LF>
  9. 0<CR><LF>
  10. 0D0!0+32051+31685<CR><LF>
  11.  
  12. 09:04:21
  13. <break>0M!00021<CR><LF>
  14. 0<CR><LF>
  15. 0D0!0+32049+31679<CR><LF>
  16.  
I would like to extract the information into the following CSV format:

Expand|Select|Wrap|Line Numbers
  1. 09:04:11,32044,31681
  2. 09:04:16,32051,31685
  3. 09:04:21,32049,31679
  4.  
any help or pseudo code would be greatly appreciated.
May 16 '11 #1
2 2651
bvdet
2,851 Expert Mod 2GB
Create an open file object for reading
Initialize an empty list to save the data
Iterate on the file object using a for loop
Start a nested for loop (for i in range(5))
Initialize a temporary list
i == 0, strip white space and append current line to temp list
i == 3, split string on "+", strip white space, append elements 1 and 2 to temp list
Advance file position one line by calling file object method next() or readline()
End of nested loop, append temp list to data list
End of file iteration
Close file object
Open file object for writing
Write data to disc
Close file object
May 17 '11 #2
Thanks for pseudo code, I got something else implemented but this is a more robust solution.
May 17 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bryan Harrington | last post by:
Hello all.. I'm working on some reports, and have added the ability to "download" the reports to excel. Not a big deal, fairly straight forward. However, PHB wants to be able to create some pivot...
2
by: Siu | last post by:
Hi, I use the following code to export and import a file Excel from resp. into a Web page with the following code: //EXPORT Response.Clear(); Response.Buffer = true; Response.ContentType =...
6
by: Sam Johnson | last post by:
HI I tried to send the following SQL string to an open databse, to export a table into excel format: g.Connection = conn 'valid OleDBConnection and Command objects g.CommandText = "SELECT *...
9
by: LimaCharlie | last post by:
Good Day to all, Hope you could help me w/ my project. Im creating a DTS Package. The source data will be coming from an excel file going to my SQL table. The DTS package is scheduled to execute...
1
by: Defacta | last post by:
Hi, When I upload an excel file, PHP does not recognize the type of this file: echo $HTTP_POST_FILES ; returns: application/octet-stream Whereas a word file returns: application/msword
1
roswara
by: roswara | last post by:
Dear all, Currently, I am working on a project to make a web-based application using ASP 2.0 and C#. This application will ask user to input for an excel file which has graphs in it. Then the...
2
by: minhtran | last post by:
HI all I wish to get help from anyone as how can I upload a file as Excel file or Text from Client side to Webserver then we can read the file in ASP.NET or any code can read the file from client....
1
by: pankaj gugale | last post by:
how do i read a excel file in c#.net
8
by: K Viltersten | last post by:
I understand that the new versions of MS Word, MS Excel etc. allow for creation of a document using XML tags (the technique or format is called OOXML, i think). I imagine that the idea behind...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.