Regex match date and seconds format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regex match date and seconds format
# 1  
Old 07-09-2015
Regex match date and seconds format

Hi

Code:
$ awk '{print $1," ",$4}' access.log | sort | uniq -c| sort -nr | head -n20
 62 192.168.10.6   [31/May/2015:15:14:40
 62 192.168.10.32   [31/May/2015:19:47:57

How can get the result like
Code:
 62, 192.168.10.6, 14:40
 62, 192.168.10.32, 47:57

I tried modifying -

Code:
$ awk '{print $1," ",$4}' access.log | sort | uniq -c| sort -nr | head -n20 | awk '{print $1","$2}'

- this print 1 and 2 with comma. Now I need the last part i,e min:sec

Thanks
Ash

Last edited by Don Cragun; 07-09-2015 at 03:50 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 07-09-2015
Try
Code:
awk '{split ($4, T, ":"); print $1," ",T[3] ":" T[4]}' file | sort | uniq -c| sort -nr | head -n20
      1 192.168.10.6   14:40
      1 192.168.10.32   47:57

This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-09-2015
"solved"
# 4  
Old 07-09-2015
If you don't care about different dates being lumped together in the output, you could also try something like:
Code:
awk '{split($4,T,":");c[$1","T[3]":"T[4]]++}END{for(i in c)print c[i]","i}' access.log|sort -nr|head -n20

which would produce output something like:
Code:
62,192.168.10.6,14:40
41,192.168.10.32,58:57
21,192.168.10.32,47:57

with an obviously different input file than you were using (since you didn't provide a sample input file). Since you didn't provide any sample input, we have no idea why you would have 62 entries in your data with the same date and time stamps (nor, if there are different month, day, year, and hour entries in your data why you would only want to print minutes and seconds), so we're making wild guesses as to what might be important in your input file.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting time format as Integer to seconds

Hello, How can we convert date like format 20181004171050 in seconds ? I can able to convert till date but failing for HHMMSS. date -d "20181004" "+%s" output as 1538596800 . But when i add hhmmss it is failing date -d "20181004172000" "+%s" result Invalid date Kindly guide. Regards (16 Replies)
Discussion started by: sadique.manzar
16 Replies

2. Shell Programming and Scripting

Pattern to match date in YYYY-MM-DD format on Linux machine

Hi Expert, Request your help. For date validation in csv file, i have written below code for linux machine I want the date to be in format 2017-05-11(YYYY-MM-DD), if not present in this format the error should be printed. Could you please help in finding the right pattern to match above date... (8 Replies)
Discussion started by: as7951
8 Replies

3. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

4. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

5. Shell Programming and Scripting

Date format in micro seconds

Can i get date format in micro seconds in unix example 2012-01-27- 12.22.04.568722 Any help is appreciable (2 Replies)
Discussion started by: srichunduru
2 Replies

6. UNIX for Dummies Questions & Answers

regex date format help

I need to write a regular expression for todays date in format 12/11/11? any help will be greatful thanks. (3 Replies)
Discussion started by: drew211
3 Replies

7. Shell Programming and Scripting

Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates. Example : date -d "2007-09-01 17:30:40" '+%s' But this gives me below error date: illegal option -- d Usage: date OS: AIX... (6 Replies)
Discussion started by: bpaac
6 Replies

8. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

10. HP-UX

a simple way of converting a date in seconds to normal date

Hi all! I'm working on a HPUX system, and I was wondering if there is a simple way to convert a date from seconds (since 1970) to a normal date. Thanks (2 Replies)
Discussion started by: travian
2 Replies
Login or Register to Ask a Question