Parse Text File and Output to File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John M. Lembo

    Parse Text File and Output to File

    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
    jlembo@rocheste r.rr.com (Alt. email)



Working...