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!

Parse part II

Status
Not open for further replies.

jonnymp316

IS-IT--Management
Jun 6, 2003
6
US
Hello,
I am a beginner with Perl and I was wondering how I could script with perl to read the output of file. In other words how can I parse the output from a dos application?

For instance I run...

C:\>status.exe
===============================
name=Jonny
value=10
status=10x2
===============================
name=Bobby
value=11
status=8x2
===============================
name=Freddy
value=11
status=8x2
C:\>

What I want to do is to get the values from the line where status is, while creating a loop that will continue to get the values until the end of the application (EOF). I want it to store the information in a text file (stored.txt). Wow this is a lot of work, but anyone that can help me that would be awesome. Thanks.

-Jonathan
 
#!/usr/bin/perl
@rc=`C:\status.exe` #backticks not apostrophes
open STORE, ">C:\stored.txt";
foreach $line (@rc) {
if (index $line, "status") {
print STORE $line;
}
}
close STORE;

Should do it
HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top