LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


Search this Thread
Old 01-29-2008, 08:24 AM   #1
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

a | 10 15
b | 10 13

i want to saw

if col2oflineb > col2oflinea


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

Any comments would be appreciated


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

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

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

print "<br>\n";

$a = split("	", $sa);
$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
LQ Newbie
Registered: Jan 2008
Posts: 2

Original Poster
Rep: Reputation: 0

Just what i needed.



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 07:10 AM.

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