Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Parse Text File and Output to File

Reply
Thread Tools

Parse Text File and Output to File

 
 
John M. Lembo
Guest
Posts: n/a
 
      08-01-2003
I am using Perl to parse a text file and output to another file. The text
file has data on Unix virtual memory (vmstat) and I want to delete lines
that I don't want and output lines that I want to a new file. The script I
have is giving me blank lines in the new file.

#!/usr/local/bin/perl
#program to read systemdata file
#and write to systemstats file
#
#
$file = '/users/rit0/g3/jml9810/metrics/systemdata';
open(INFO, $file); #opens file systemstats
open(DATA, ">systemstats");#file to write data to
@lines = <INFO>; #assigns lines to array

foreach $line (@lines) #go through each line in file
{
if ($line ^V)
{
$line =~ s/$line//;
}

DATA == $line;
print DATA "\n";
}

close(INFO); #closes file
close(DATA);

The data I am reading is vmstat as follows:

0308011610
Virtual Memory Statistics: (pagesize = 8192)
procs memory pages intr cpu
r w u act free wire fault cow zero react pin pout in sy cs us sy
id
5 483 41 113K 43K 34K 958M 15M 36M 48K 17M 3716 88 1K 914 2 5
93
=== end at Fri Aug 1 12:10:01 EDT 2003 ===
0308011615
Virtual Memory Statistics: (pagesize = 8192)
procs memory pages intr cpu
r w u act free wire fault cow zero react pin pout in sy cs us sy
id
5 496 35 114K 43K 33K 958M 15M 36M 48K 17M 3716 88 1K 914 2 5
93
=== end at Fri Aug 1 12:15:01 EDT 2003 ===

I want to output the date and memory data only to a new file and delete the
other lines. Any help is appreciated.

--

Regards,

John M. Lembo
(585) 594-1753 (ET)
(585) 594-4028 Fax
http://www.velocityreviews.com/forums/(E-Mail Removed) (Alt. email)



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: text file search to text file output possible? Whiskers Computer Support 3 10-07-2006 06:32 PM
Re: text file search to text file output possible? Mitch Computer Support 0 10-06-2006 11:15 PM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
My simple script parse output screen and to a new file! chuck amadi Python 11 06-16-2004 10:10 PM
Parse Text File and Output to File John M. Lembo Perl Misc 2 08-01-2003 09:52 PM



Advertisments