Parse Text File and Output to File

Discussion in 'Perl' started by John M. Lembo, Aug 1, 2003.

  1. 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
    (Alt. email)
     
    John M. Lembo, Aug 1, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chuck amadi
    Replies:
    11
    Views:
    670
    Cameron Laird
    Jun 16, 2004
  2. chuck amadi
    Replies:
    1
    Views:
    493
    Larry Bates
    Jun 23, 2004
  3. Replies:
    19
    Views:
    1,137
    Daniel Vallstrom
    Mar 15, 2005
  4. John M. Lembo

    Parse Text File and Output to File

    John M. Lembo, Aug 1, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    166
    JS Bangs
    Aug 1, 2003
  5. Jack
    Replies:
    2
    Views:
    194
    Dave Weaver
    Jan 7, 2008
Loading...

Share This Page