Computing.Net > Forums > Unix > sort problem

sort problem

Reply to Message Icon

Original Message
Name: isaac
Date: November 15, 2006 at 03:46:08 Pacific
Subject: sort problem
OS: unix
CPU/Ram: unix
Model/Manufacturer: unix
Comment:

Hi everybody. I've got a problem.I need to sort a file by teh 4th column (it's a date). I attach two rows of the file:
127.0.0.1 - - [01/Nov/2006:15:03:11 +0100] "GET /_oracle_http_server_webcache_static_.html HTTP/1.1" 200 99 "95689802227,0"
127.0.0.1 - - [02/Aug/2006:15:41:49 +0200] "GET /_oracle_http_server_webcache_static_.html HTTP/1.1" 200 99 "91313042432,0"

In theory, the 02/Aug/2006 must be before that 01/Nov/2006

Thank you
Isaac.



Report Offensive Message For Removal


Response Number 1
Name: nails
Date: November 15, 2006 at 10:58:34 Pacific
Subject: sort problem
Reply: (edit)

Your best bet is to go cycle thru the file changing each date to a numeric, year-month-day format and then sort it. i.e.

02/Aug/2006 -> 20060802
01/Nov/2006 -> 20061101

and then sort numerically on that field.
If it were me, I'd use awk and parse the 4th field using the / as a delimiter. If you need it, I might be able to help.

Sorry, but I see no easy way to do it.


Report Offensive Follow Up For Removal

Response Number 2
Name: Devaraj (by Fidy)
Date: November 16, 2006 at 00:40:06 Pacific
Subject: sort problem
Reply: (edit)

This little trcik may help you...

#!/bin/ksh
cut -c 16-26 inputfile > cutsort
sort -t "/" -k 3,3 -M -k 2,2 -k 1,1 cutsort > sorted
for i in `cat sorted`
do
grep $i inputfile >> outfile
done

Make sure you clear outfile when u have to run twice.

-Devaraj Takhellambam

Regards,
Devaraj Takhellambam


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: sort problem

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge