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

Split file into several and reformat

Hi,

I want to take read an input file (sels.txt) that looks like:

Begin sels
sel1 = {1001, 1002, 1003, ...
...
1099}

sel2 = {1001, 1008, 1009 ...
...
1299}
End sels

And turn it into an output file for each of the "sels" in the input file,i.e
sel1.txt:

L1001
L1002
L1003
....
L1099

and sel2.txt:

L1001
L1008
L1009
....
L1299

And so on. Many thanks,
Wayne
Jun 21 '07 #1
3 1291
bo******@aapt.net.au a écrit :
Hi,

I want to take read an input file (sels.txt) that looks like:
(snip)
>
And turn it into an output file for each of the "sels" in the input file, i.e
sel1.txt:
(snip)
and sel2.txt:
(snip)

And so on.
Yes, fine. All this is documented here:

http://www.catb.org/~esr/faqs/smart-...ns.html#before
Many thanks,
You're welcome.
Jun 21 '07 #2
On Jun 20, 10:45 pm, bombe...@aapt.net.au wrote:
Hi,

I want to take read an input file (sels.txt) that looks like:

Begin sels
sel1 = {1001, 1002, 1003, ...
...
1099}

sel2 = {1001, 1008, 1009 ...
...
1299}
End sels

And turn it into an output file for each of the "sels" in the input file, i.e
sel1.txt:

L1001
L1002
L1003
...
L1099

and sel2.txt:

L1001
L1008
L1009
...
L1299

And so on. Many thanks,
Wayne
hehe...

After Bruno's suggested read, go here: http://docs.python.org/tut/

Look at the string module.. specifically .strip() and .split(",")
Also look at reading files and perhaps lists.

for line in open("filename.txt", 'r').readlines():
handle_the_line()

Good Luck.

~Sean

Jun 21 '07 #3
On 2007-06-21, bo******@aapt.net.au <bo******@aapt.net.auwrote:
Hi,

I want to take read an input file (sels.txt) that looks like:

Begin sels
sel1 = {1001, 1002, 1003, ...
...
1099}

sel2 = {1001, 1008, 1009 ...
...
1299}
End sels

And turn it into an output file for each of the "sels" in the input file, i.e
sel1.txt:

L1001
L1002
L1003
...
L1099

and sel2.txt:

L1001
L1008
L1009
...
L1299

And so on. Many thanks,
I think I'd put together a simple grammar and then write a
recursive descent parser that spit out my output files. But
that's just because I find that kind of thing fun. ;)

--
Neil Cerutti
I'm tired of hearing about money, money, money, money, money. I just want to
play the game, drink Pepsi, wear Reebok. --Shaquille O'Neal
Jun 21 '07 #4

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

Similar topics

2
by: nieuws | last post by:
Hi, I was trying to do the following. It's my first php "project", so it's quiet logic that i have some problems. Perhaps the php community might help. It's about this : I have a txt file...
21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
1
by: TJ | last post by:
I am very new to C# (this is my first real project), therefore please be patient if my question is considered being to newbie. I am modifying a program which takes a text file, does some...
8
by: Paul | last post by:
I have looked and looked for this info. All the I/O examples I've found either explicity use a file name or use the OpenFileDialog. When you drag a MS Word document over MS Word, it launches and...
2
by: noopathan | last post by:
Hi experts , I have an excel file in the below format --------------------------------------------------------------------- CodeID CodeName Market Name Date...
6
by: Vlado Jasovic | last post by:
Hello, We're developing application in VS2005 using vb.net. Our application exe file is ~20mb when compiled. Recently, we have developed auto-update feature that goes on our web-site,...
1
by: Query Builder | last post by:
I have one of our production Accounting Databases starting from 2 GB now grown into a 20 GB Database over the period of a few years... I have been getting timeouts when transactions are trying to...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
7
by: John Smith | last post by:
Hi, I am very new to C# and NET framework. I am trying to hash (using MD5CryptoServiceProvider) a source that is split into several files. Now when the source is in one file I can produce the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.