The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2006
pieman8080 pieman8080 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 12
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
  #2 (permalink)  
Old 11-17-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Can't you sort the last date field ie., 20060530-12:35
Code:
sort -t"-" -k2.1,2.8 -k3.1,3.5 inputlogfile
Just define the field sep as "-"

Edit - I just noticed a "-" early in the string. You may need another way to define fields.
  #3 (permalink)  
Old 11-18-2006
futurelet futurelet is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 137
Code:
ruby -e 'puts ARGF.sort_by{|s| s.chomp[-14,14]}'  myfile
  #4 (permalink)  
Old 11-20-2006
pieman8080 pieman8080 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 12
I don't have ruby installed. Is there any way to do it using sort?
  #5 (permalink)  
Old 11-21-2006
nilesrex nilesrex is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 43
try this

sort -t\; -k5,5 inputfile
  #6 (permalink)  
Old 11-21-2006
pieman8080 pieman8080 is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 12
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0