I Need Help with AWK and UNIX

Discussion in 'OT Technology' started by Drifter87, Nov 2, 2007.

  1. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0
    I have no idea how to do this using AWK and UNIX. Once I get to step two everything goes down hill. How do I get the first date and the last date? I have been at this for 3 hours now and I am still no where.

    Yes this is Home Work for school, normally once I see something that works I can understand everything, but this professor does NOT give examples so I am always confused as to what is going on and how things actually work.
    Any help would be awesome!, google just seems to give me the run around.

    The Assignment:

    Code:
     1)display the following header:
           [B][FONT=&quot]WEBLOG REPORT GENERATOR by <yourname>
      ==========================================[/FONT][/B]
      2)In a single sentence on the next line: 
      a)display the starting date and time of the data file
      b)display the ending date and time of the data file
       
      
      3)In a single sentence on the next line:
      a)display the number records (hits) in the file
      b)display the number of days covered by the data files
      c)display the average number of hits/day
    
     
     
      4)In a single sentence on the next line:
      a)display the single busiest date and hour (i.e. minutes between :00 & :59)
      b)display the percentage of total hits that occurred in this time period
    
     
     
      5)In a single sentence on the next line:
      a)display the addresses of the 3 clients that made the most hits on the server
      b)display the percentage of total hits from each client
      Your output should look similar to the following (line wraps will depend on output device):
       
      [FONT=&quot]        WEBLOG REPORT GENERATOR by I.M. Kuhl
    ==========================================[/FONT]
      [FONT=&quot]Report covers the period from 18-Dec-2003 at 19:26:16 to 24-Dec-2003 at 18:37:47.[/FONT]
      [FONT=&quot]There were 456 hits in 7 days for an average of 65 hits/day.[/FONT]
      [FONT=&quot]The busiest time for this log period was 19-Dec-2003 between 10:00pm  and 10:59pm (17%).[/FONT]
      [FONT=&quot]The most hits were from: 111.22.33.44 (15%)   111.2.5.6 (14%)  129.21.26.133 (12%).[/FONT]
      
    
    
    Sample File:
    Code:
    129.21.140.41 - - [19/Dec/2003:22:30:18 -0500] "GET /~user/pics/p7+p8/DSC00333.J
    PG HTTP/1.1" 200 62758 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:22 -0500] "GET /~user/pics/p7+p8/DSC00334.J
    PG HTTP/1.1" 200 61552 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:26 -0500] "GET /~user/pics/p7+p8/DSC00335.J
    PG HTTP/1.1" 200 41819 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:30 -0500] "GET /~user/pics/p7+p8/DSC00336.J
    PG HTTP/1.1" 200 46735 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:33 -0500] "GET /~user/pics/p7+p8/DSC00338.J
    PG HTTP/1.1" 200 81881 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:39 -0500] "GET /~user/pics/p7+p8/DSC00339.J
    PG HTTP/1.1" 200 40243 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:42 -0500] "GET /~user/pics/p7+p8/DSC00340.J
    PG HTTP/1.1" 200 51663 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:45 -0500] "GET /~user/pics/p7+p8/DSC00341.J
    PG HTTP/1.1" 200 54178 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:48 -0500] "GET /~user/pics/p7+p8/DSC00342.J
    PG HTTP/1.1" 200 38035 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:51 -0500] "GET /~user/pics/p7+p8/DSC00343.J
    PG HTTP/1.1" 200 35393 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    129.21.140.41 - - [19/Dec/2003:22:30:53 -0500] "GET /~user/pics/p7+p8/DSC00344.J
    PG HTTP/1.1" 200 51760 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (comp
    atible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    21.140.41 - - [19/Dec/2003:22:30:56 -0500] "GET /~user/pics/p7+p8/DSC00345.JPG H
    TTP/1.1" 200 83047 "http://website.com/~user/pics/p7+p8/" "Mozilla/4.0 (compatib
    le; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"
    
    
    
     
  2. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,278
    Likes Received:
    555
    In for later. If you don't have an answer by then, I'll take a look at it after work.
     
  3. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0
    Thank You :wavey:

    I got the other task of this Home Work done, just I get to this and AWK and my world falls apart.
     
  4. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0
    I think

    Code:
    { date[i]=substr($4,2); i++}
    
    took care of my date issue, now I can just point to the array which dates I want...

    Now I am trying to figure out




    4)In a single sentence on the next line:
    a)display the single busiest date and hour (i.e. minutes between :00 & :59)
    b)display the percentage of total hits that occurred in this time period



    5)In a single sentence on the next line:
    a)display the addresses of the 3 clients that made the most hits on the server
    b)display the percentage of total hits from each client
     
    Last edited: Nov 2, 2007
  5. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    I don't have an answer. I'm just amazed they still teach awk.
     
  6. Drifter87

    Drifter87 Yippi-kay-ay, Motherfucker

    Joined:
    Jan 5, 2005
    Messages:
    7,173
    Likes Received:
    0

    :hs:
     
  7. DouggieJ

    DouggieJ OT Supporter

    Joined:
    Nov 1, 2007
    Messages:
    8,126
    Likes Received:
    0
    Location:
    New York, NY USA
    Yeah, I think Perl replaced that a long time ago.
     

Share This Page