Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie with parsing

Status
Not open for further replies.

flnMichael

Programmer
Nov 13, 2003
96
US
Hey guys,
I am trying to get a couple of lines of a text file and parse the lines into individual variables and output them in another formatted text file. Here's what I have so far:

Code:
...previous code...

elsif($line =~ /^TEST STATION NUMBER:/)
{
$test_set_id =~ (/^TEST STATION NUMBER:\s*(.*)s+TEST TYPE:\s*(.*)/);
$test_set_id =~ s/\s+//g;
print "TEST_SET_IDENTIFICATION = $test_set_id\n";
}

and here's the portion of text I need to parse:

GCS SERIAL #: 0111
TEST STATION NUMBER: 555 TEST TYPE: SALE
OPERATION: 180
DATE: 06/03/02 TIME:11:02:58
PAYROLL NUMBER: t7419 TEST CODE: 1
QAP NUMBER: 759150 QAP REVISION: 58

I can get the single entry lines just fine, but it's the line where there are multiple entries I'm having trouble with. Pretty much every entry you see in this portion of text needs to be in a variable so I can easily output it in the next text file.

Any help would be appreciated.

Thanks
Mike
 
explain this comment better:

I can get the single entry lines just fine, but it's the line where there are multiple entries I'm having trouble with.

use examples of what you have (like your data) and what you want to get out of it.
 
sorry, it's parsing this line where I have no problem:

GCS SERIAL #: 0111

but this line is where I have the problem:

TEST STATION NUMBER: 555 TEST TYPE: SALE

I need the first line to output:

SERIAL_NUMBER = 0111

and the second line:

TEST_STATION = 555
TEST_TYPE = SALE

and so on for the rest of the lines where each entry will be placed into a variable. Sample output (everything in () is not part of the output):

GCS SERIAL = 0111 (var $serial)
TEST STATION NUMBER = 555 (var $test_set_id)
TEST TYPE = SALE (var $test_type)
OPERATION = 180 (var $operation)
DATE = 06/03/02 (var $date)
TIME = 11:02:58 (var $time)
PAYROLL NUMBER = t7419 (var $operator)
TEST CODE = 1 (var $test)
QAP NUMBER = 759150 (var $qap)
QAP REVISION = 58 (var $qap_rev)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top