![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting a file | mtechnocrat | UNIX for Dummies Questions & Answers | 11 | 06-28-2007 07:28 AM |
| file sorting | phani_sree | Shell Programming and Scripting | 5 | 02-05-2007 02:39 AM |
| Sorting a file | Khoomfire | Shell Programming and Scripting | 2 | 12-13-2005 07:48 AM |
| sorting file | sx3v1l_1n51de | Shell Programming and Scripting | 4 | 06-22-2005 01:16 PM |
| Help sorting file. | gio123bg | Shell Programming and Scripting | 3 | 12-10-2003 10:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
need help with sorting a file
I'm trying sort a log file (text file) from oldest to newest. Each line of the file has an output like:
service;username;release_number_number;environment;<date>;service-environment-<yyyyddmm>-<mm:ss> the <date> format are like the following examples: Fri Nov 17 06:33:13 PST 2006 Thu Nov 16 15:36:00 PST 2006 Here is an example of a real entry in my log file: testapp;jhill;11_11-11;st;Tue May 30 12:35:00 PDT 2006;testapp-st-20060530-12:35 Ok so you get the idea. Here's my issue. I have a log file similar to this on 2 different servers and I want to combine them. I know i can cat one file and append to the other, but I want to them have in order as far as date. If I append 1 file to the other, what command could i use to sort? Spefically I'm trying to sort the <date> field above. Thanks |
|
||||
|
Can't you sort the last date field ie., 20060530-12:35
Code:
sort -t"-" -k2.1,2.8 -k3.1,3.5 inputlogfile Edit - I just noticed a "-" early in the string. You may need another way to define fields. |
|
||||
|
That's close. That sorted it by the time, so in the example below:
testapp;jhill;11_11-11;st;Tue May 30 12:35:00 PDT 2006;testapp-st-20060530-12:35 It sorted it by the "12:35:00" time. But I need it sorted by the day and time, or the "May 30 12:35:00" part. Is there a way to sort both? thx |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|