[HPADM] SUMMARY: Parse file using awk

From: Hazari Shyam (WQQ1SXH) (WQQ1SXH_at_ups.com)
Date: 09/17/03

  • Next message: HAUTECOEUR Bruno: "[HPADM] building mod_jk"
    To: hpux-admin@DutchWorks.nl
    Date: Wed, 17 Sep 2003 16:45:38 -0400
    
    

    I received three replies and I ended up using Brett Geer's Script. I added
    few more steps to suit to my requirement.
    Here is the script.

    ----------------------begin script-----------------------------------
    #!/bin/ksh

    awk -F"," ' BEGIN { vTOTAL=0 ; vFILE=0 }
    {
       RLENGTH = length($5)
       vNUMBER = substr ($5, 1, RLENGTH-4)
       vTYPE = substr ($5, RLENGTH-2, RLENGTH)
       if (vTYPE == " MB")
          (vNUMBER = vNUMBER / 1024)
       if (vTYPE == " KB")
          (vNUMBER = vNUMBER / 1048576)
       vTOTAL += vNUMBER + 0
       vFILE = substr ($6, index (" ", $6))
       vFILET += vFILE + 0
    }

    END { print vTOTAL " " vFILET }' < webreport

    ---------------------------end script-------------------------------------
    Also I received replies from David Totch and Ronell. I haven't tested them
    yet.

    Thank you So much !!!

    -Shyam

    2)
    Try something like this:
    BEGIN {
    FS="," # set field separator to comma
    # use the factors for division (and you thought I was gonna mutiply...)
    factor["KB"]=1024*1024
    factor["MB"]=1024
    factor["GB"]=1
    }
    {
    split($5,array," ") # need the number and dimension separately
    printf(">%s< ]%s[ %s\n",array[1],array[2],array[1]/factor[array[2]])
    # this just checks conversions, you will need to total.
    }
    -David T

    3)

    awk ' BEGIN {
    FS = ","
    in_file = /in/file/path/name
    out_file = /out/file/path/name
    read_in = "cat " in_file
    While (read_in | getline) {
    fs_size_info = $5
    ### get the number
    fs_size = substr(fs_size_info,1,len(fs_file_info)-3)
    ### get the type
    fs_size_type = substr(fs_size_info,len(fs_size_info)-1,len(fs_size_info))
    ### change to GB
    if (fs_size_type != "GB") {
    if (fs_size_type == "KB") {
    fs_size = fs_size/1024/1024
    }
    if (fs_size_type == "MB") {
    fs_size = fs_size/1024
    }
    }
    fs_size_info = fs_size " GB
    ### if you want to print the new output to a file
    print $1 "," $2 "," $3 "," $4 "," fs_size_info "," $6 >> out_file
    ### to get the totals
    tot_size = tot_size + fs_size
    tot_files = tot_files + $6
    }
    close(read_in)
    }'
    This is all off the top of my head so you may need to change a few details
    but you should get the idea.
    -Ronelle van Niekerk

    Original Question
    Admins,
    I got a file in comma separated format and I would like to parse it. I would
    like to add the size and no of files column to get a grand total. As you see
    some of the contents for size column are in KB,GB and MB. I would like to
    convert KB and MB to GB before getting a grand total.

    FileSystem Status Date/time Duration Size No
    of Files
    u001/app/oracle/oradata/iasdb,File Failure,9/15/03 8:14 PM,00:09:28,516.963
    MB,30
    /u001/app/oracle/product/ias/9.0.2.0.1/inf,File Failure,9/15/03 8:29
    PM,01:09:00,4.105 GB,420
    /var,File Failure,9/15/03 9:06 PM,00:24:18,1.084 GB,3988
    /usr,File Failure,9/15/03 6:26 PM,00:17:27,30.668 MB,27
    /u001/app/oracle/product,File Failure,9/15/03 8:40 PM,00:19:20,766.586 MB,71

    /data/UPS/prod_flows,File Failure,9/15/03 7:50 PM,00:28:42,1.737 GB,174
    /data/UPS/prod_flows,File Failure,9/15/03 7:50 PM,00:28:42,1.737 GB,174
    /u001/app/oracle/product,File Failure,9/15/03 9:37 PM,00:02:57,26.604 MB,11
    /D/,File Failure,9/15/03 6:32 PM,00:57:01,3.288 GB,181
    /C/,File Failure,9/15/03 6:46 PM,00:00:44,135.000 KB,20
    /H/,File Failure,9/15/03 9:00 PM,05:23:36,46.717 GB,296690
    /H/,File Failure,9/15/03 9:00 PM,01:19:02,1.757 GB,768
    /C/,File Failure,9/15/03 9:09 PM,00:00:36,5.463 MB,52
    /W/,File Failure,9/15/03 9:17 PM,00:08:17,7.000 KB,10
    I am looking for a simple awk snippet.

    -Shyam

    --
                 ---> Please post QUESTIONS and SUMMARIES only!! <---
            To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
           Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
     
     Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
                http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)
    

  • Next message: HAUTECOEUR Bruno: "[HPADM] building mod_jk"

    Relevant Pages

    • Re: Script error in OE6 html email
      ... That makes sense in that it only happens in replies and not new ... It could be that one of those is including the script as a means to ... When it arrives in her inbox, the line of code has been added. ... ::: As well any original emails are from the default account. ...
      (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
    • Re: inserting dot
      ... > thanks for your replies, I looked into the substr thingy, and made ... > this little script.. ... but i'm getting this strange error message: ...
      (comp.lang.perl.misc)
    • Re: Can I modify the date headers in received messages?
      ... sent (replies) in the same folder, and want those replies to be listed ... The script worked great as an application but for some reason I ... > set currentMessages to the current messages ... > repeat with theMsg in the currentMessages ...
      (microsoft.public.mac.office.entourage)
    • Re: Domain logon script runs minimised
      ... PLEASE post all messages and replies in the newsgroups ... > Windows 2000 Professional workstations. ... > netlogon script from that server's netlogon share. ...
      (microsoft.public.win2000.general)
    • Re: Domain logon script runs minimised
      ... PLEASE post all messages and replies in the newsgroups ... > Windows 2000 Professional workstations. ... > netlogon script from that server's netlogon share. ...
      (microsoft.public.win2000.networking)