/    Sign up×
Community /Pin to ProfileBookmark

Need to parse a text file, saving certain columns

I’ve always browsed this site for PHP and Perl articles, but never needed to post before. anyway.

I’ve got a file that contains Intro text, a table with whitespace used to separate the columns, and a summary paragraph. The only parts of the file I care about are accessing three of the columns.

I need to access the AGC, TWC, and DWC fields below, and create a new file with only the values from those columns. I’m having difficulty figuring out how to open the file, and skip the paragraphs surrounding the data. Can anyone help me out? here’s the data file

04-22-09-NO42009

blank text


———————————————————————————

HGT AGC COMP TWC DWC
———————————————————————————

20 33.0 234 11 222
23 32.3 342 2 223
43 31.0 234 2 224
59 31.4 432 4 225
68 30.0 564 5 226
70 29.2 544 7 227

Summary

04-23-09-NO42009

blank text


———————————————————————————

HGT AGC COMP TWC DWC
———————————————————————————

22 39.0 233 7 233
24 38.3 343 8 234
45 37.0 231 8 235
54 37.4 432 5 236
66 36.0 569 5 237
74 35.2 544 4 238

Summary

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tecknoauthorApr 29.2010 — edit: the columns should have more than just one space in between, but the forum collapsed the space when I posted it
Copy linkTweet thisAlerts:
@enduroxMay 28.2010 — I have a similar question, in the mean time here is a possible start:

[code=php]
$fileName="FILENAME.TXT";
$ft=fopen($fileName, "r") or die ("Unable to open the file $filename");
while(!feof($ft)){
$lines1 = fgets($ft);
$lines3 = explode(" ", $lines1);
print "$lines3[0]$lines3[1]$lines3[2]<br />";
}
fclose($ft);
[/code]
×

Success!

Help @teckno spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...