473,326 Members | 2,815 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,326 software developers and data experts.

grabbing portions of a file to output files

hi.
I have a file with this kind of structure:

Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
..........
......
......
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
....
.....
....
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
......
.....
and so on....lines starting with 'H' are headers. I wish to get the
parts of the file
where line start with 'H' all the way till before the next 'H' and save
to files of different names...how is the best way to do it ?
thanks

May 22 '06 #1
1 1148
s9************@yahoo.com wrote:
hi.
I have a file with this kind of structure:

Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.........
.....
.....
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
...
....
...
xxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.....
....
and so on....lines starting with 'H' are headers. I wish to get the
parts of the file
where line start with 'H' all the way till before the next 'H' and save
to files of different names...how is the best way to do it ?
thanks


Something like this?

out = None
for line in open(...):
if line.startswith('H'):
if out:
out.close()
out = open(..., 'w')
if out:
out.write(line)
out.close()

Kent
May 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nadie | last post by:
Greeting list readers, I noticed that the wave read object has an *implementation dependent* setpos(pos) method. When reading audio files, it is useful to be able to set the position to a...
3
by: Debbie Carter | last post by:
Can XML files be easily encrypted?
1
by: PK9 | last post by:
I'm building a windows app using C#. The goal is to merge portions of multiple xml files into one. I currently have an .xsl stylesheet that pulls in the required sections of multiple xml files...
1
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
5
by: sck10 | last post by:
Hello, I am working on a new project where I need to: 1. open an email and then create an xml file from the email 2. open the xml file and parse the information. I would like to be able to do...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
29
by: Amer Neely | last post by:
I've got a dynamically built form with checkboxes for each element ( a list of file names in a directory). I need to grab only those checkboxes that are checked, so I can then delete those files. ...
4
by: Efrat Regev | last post by:
Hello, Suppose I want to run from within a Python GUI app some long-output shell call. For example, from within Python I might want to call g++ foo.cpp I already know there are many ways to...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.