LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-29-2008, 08:24 AM   #1
8rucech85
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Rep: Reputation: 0
Best Way to manipulate a text file.. php ?


I have a tab delimited text file from which i want to compare each successive pair of lines and depending on the result drop one of the lines.

What method would be easiest for this ?

I am running RHE

Example
---------------
a | 10 15
b | 10 13


i want to saw

if col2oflineb > col2oflinea

{
lineb=null;
}

I’m fairly familiar with php but usually doing this with a database not text files...

Any comments would be appreciated

Regards

Bruce
 
Old 01-30-2008, 12:19 AM   #2
rubadub
Member
 
Registered: Jun 2004
Posts: 233

Rep: Reputation: 33
here's an example, rather messy but it is late...
Code:
<?php
$sa = "a	|	10	15";
$sb = "b	|	10	13";

print "a: '".$sa."'<br>";
print "b: '".$sb."'<br>";

print "<br>\n";

$a = split("	", $sa);
print_r($a);
$b = split("	", $sb);

print "<br>\n";

print "Therefore:<br>\n";

$sc = ($a[3] > $b[3]) ? ($sa) : ($sb);
print "c: '".$sc."'<br>";
?>
 
Old 01-30-2008, 04:35 AM   #3
8rucech85
LQ Newbie
 
Registered: Jan 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks,

Just what i needed.

Regards
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache 1.3 - .php file ain't parsed, only text misstajah Linux - Server 4 09-21-2006 06:14 AM
parsing text file in php ohcarol Programming 1 08-25-2006 09:18 AM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
php script can not write text file lemotion Linux - Newbie 5 04-20-2004 10:14 PM
Text File DB -> PHP DeadlySin3 Programming 11 05-13-2003 12:15 PM


All times are GMT -5. The time now is 05:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration