Need help with awk and access log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with awk and access log
# 1  
Old 08-13-2012
Need help with awk and access log

when i run this command:

Code:
tail -200 /var/log/httpd/access_log | awk -F'[][]' '{sub(/:[^:]*$/,"",$2);print $2}'

i get:

Code:
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56
13/Aug/2012:20:56

now i need to alter the awk command to instead output:

Code:
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20
13/Aug/2012:20

The difference is, in the second output, i want would like to get rid of the minute and leave only the hour.

shell: bash
os: linux/sunos
# 2  
Old 08-13-2012
Try:
Code:
tail -200 /var/log/httpd/access_log | awk -F'[][]' '{sub(/:[^:]*:[^:]*$/,"",$2);print $2}'

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 08-13-2012
Code:
tail -200 /var/log/httpd/access_log | awk -F'[][]' '{sub(/:[^:]*:[^:]*$/,"",$2);print $2}'

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 08-13-2012
thanks guys! can someone please explain the awk command to me? i'm falling deeper in love with awk lol
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to find time difference between HTTP PUT and HTTP DELETE requests in access.log

Hi, I'm trying to write a script to determine the time gap between HTTP PUT and HTTP DELETE requests in the HTTP Servers access log. Normally client will do HTTP PUT to push content e.g. file_1.txt and 21 seconds later it will do HTTP DELETE, but sometimes the time varies causing some issues... (3 Replies)
Discussion started by: Juha
3 Replies

2. Shell Programming and Scripting

Unable To access array in awk

Hi, i have the following code in which i am passing array tldn in awk using -v option & despite of that condition is not getting matched,can somebody suggest how to handle shell arrays in awk tcount=(9875 9667) awk -F"\t" -v ltldn="${tldn}" 'NR==FNR {POSTPAIDMDNS=$2"|"$3;next} ... (6 Replies)
Discussion started by: siramitsharma
6 Replies

3. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

Parsing out access.log with awk and grep

In part of my script I use awk to pull out the urls. awk '{print $8}' then I take them and send them to grep.` Some of them are straight .com/ or .org or whatever (address bar entries), while others are locations of images, js, etc. I'm trying to only pull any line that ends with .com/... (11 Replies)
Discussion started by: druisgod
11 Replies

5. UNIX for Dummies Questions & Answers

file access log

hi, i would like to know if there is a way to record o view a specific file access history. What i want to do is get information about what process or application has changed a text file for example. thanks in advance (2 Replies)
Discussion started by: jorgelopez100
2 Replies

6. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

7. Shell Programming and Scripting

Access Awk Variables Outside Scope

My awk script searches for specified patterns in a text file and stores these values into mem variables. Once this is done I want to Insert these values into a table. How can I avail of the variable values outside the scope of awk script.... One method that I have tried is to write the... (7 Replies)
Discussion started by: Amruta Pitkar
7 Replies

8. Shell Programming and Scripting

Access value outside awk

Hello I am new to Unix. Please help me out. My Scenario: I am first collecting all the file names present in the directory with structure myinfo/yourinfo/supplierinfo I have four files with the names myCollector.java, yourCollector.java, someCollector.java, everyCollector.java. in the directory.... (1 Reply)
Discussion started by: jason.bean
1 Replies

9. UNIX for Dummies Questions & Answers

Access value outside awk or split value of array

Hello I am new to Unix. Please help me out. My Scenario: I am first collecting all the file names present in the directory with structure myinfo/yourinfo/supplierinfo I have four files with the names myCollector.java, yourCollector.java, someCollector.java, everyCollector.java. in the directory.... (1 Reply)
Discussion started by: jason.bean
1 Replies

10. UNIX for Advanced & Expert Users

Access Awk Variables Outside Scope

Sorry in the wrong forum. Moving this to right forum. (2 Replies)
Discussion started by: Amruta Pitkar
2 Replies
Login or Register to Ask a Question