473,320 Members | 1,535 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,320 software developers and data experts.

Reading a specific line in a text file

Hi,

I need a help regarding reading a line in a text file. I have some files with columns but some header information at the top. Some of these header lines begin with a *, and some of them with nothing. I have to read the 9th line and 5th column, then extract the number from here and save it to another text file.

I was thinking of some solutions.
1) I can delete the first 8 lines and read the columns straightforward.
2) I first read the 9th line and then the 5th column, by using f.readline() or etc. However, readline only reads the first line and I could not tell to read the 9th line.

I could not made neither of those solutions. The second would be much better because at the end I do not lose the header info. I have hundreds of these files, any help would be much appreciated.

Thanks
Apr 28 '09 #1
3 16492
micmast
144 100+
you could read the entire file in an array and use that array like this
array[8]
and continue from there on out
Apr 28 '09 #2
bvdet
2,851 Expert Mod 2GB
micmast's suggestion should work by using file method f.readlines(). List index 0 is your header and index 8 is your line of data. Assuming the separator is a comma:
Expand|Select|Wrap|Line Numbers
  1. f = open(file_name)
  2. fileList = f.readlines()
  3. f.close()
  4. fifth_column = fileList[8].split(',')[4]
Apr 28 '09 #3
Great, it is working perfectly.

Thanks a lot...
Apr 28 '09 #4

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

Similar topics

40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
2
by: Einvalt | last post by:
My program keeps a text file list of co-ordinates, for example: 3,5 2,7 12,9 5,6 ... and so on, indefinitely. How do I read the values from the nth line into variables X,Y - say if I...
13
by: ACC | last post by:
Hi! I'm developing an application to analyze some information that is inside a text file. The size of the text file goes from 50Mb to 220Mb... The text file is like a table, with "rows" and...
3
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
1
by: Vangos | last post by:
Hi. I am an amateur Visual C# programmer and I need your help... I have created a program that opens a text file for reading its contents. I want the program to read a specific line (for...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
3
by: Ahmad Jalil Qarshi | last post by:
Hi, I have a text file having size about 2 GB. The text file format is like: Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values For example...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.