Welcome to the most active Linux Forum on the web.
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 08-25-2006, 05:44 AM   #1
Registered: Dec 2004
Location: Nepal
Posts: 86

Rep: Reputation: 15
parsing text file in php

I have these line in a text file called file.txt.

1 ::lfp ::eth1 ::eth0 :: ::1 ::48 ::48 ::28 ::32 ::20
1 ::xzone ::eth1 ::eth0 :: ::1 ::48 ::48 ::28 ::32 ::21
#1 ::lec ::eth1 ::eth0 :: ::1 ::64 ::64 ::32 ::32 ::22
1 ::test ::eth1 ::eth0 :: ::1 ::48 ::48 ::32 ::32 ::23

I want to parse these file so that only select text can be dislpayed. if there is comment on the line with "#" then that line should be skipped. How can I do that?

Output should be

Name: ipaddress: down: up: id:
lfp 48 28 20
zone 48 32 21
test 48 32 23

I have written this script but it didn't help


$filename = "file.txt";
$fp = fopen("$filename", "r") or die("couldnot open a file");
while (!feof($fp)){
$line = fgets($fp, 1024);
if(preg_match("/^#/", $line) ){
$client = split("eth0|eth1|::", $line);
foreach($client as $line)
print "$line<br>";


Any help
Old 08-25-2006, 09:18 AM   #2
Senior Member
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,189

Rep: Reputation: 49
try using the cut command, something more like
cut -d:: -f1 file.txt


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
I need help parsing text from a text file rsmccain Linux - General 2 01-05-2006 02:43 PM
Need help parsing text file scilec Programming 5 12-02-2004 01:00 PM
need help parsing text file airman99 Linux - General 2 10-08-2004 09:09 PM
Parsing Text from a html file. Rezon Programming 6 10-18-2003 12:09 AM
Parsing a file for a string of text jamesmwlv Linux - General 2 12-02-2002 07:13 PM

All times are GMT -5. The time now is 03:10 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration