Solved

Need help sorting a text file

Posted on 2006-12-01
5
201 Views
Last Modified: 2010-04-22
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?

Again, I'm spefically trying to sort the <date> field above. Thanks

One note, I did the following: sort -t\; -k5,5 inputfile , but that it by the time "12:35:00" time in the above example, not the entire date and time as specified in <date>. I'm not even sure if the sort command can do this.
0
Comment
Question by:pieman8080
  • 2
  • 2
5 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 18055622
cat file1 file2 | perl -ne 'split/\;/; $t=`date +%s -d "$_[4]"`; chop($t); print "$t:$_";' | sort -n | cut -d: -f2-
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 18055668
sort -n -t ";" -k 6,6 file1 file2 > file3

file3 is the combine log file.
0
 

Author Comment

by:pieman8080
ID: 18056179
Thanks ravenpl, that worked. I need one more thing. How do i eliminate mulpitle entries of the same line. There were some lines that were in both files so when i did the cat, it created multiple entries. thx
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 18056192
cat file1 file2 | perl -ne 'split/\;/; $t=`date +%s -d "$_[4]"`; chop($t); print "$t:$_";' | sort -n | cut -d: -f2- | uniq
0
 

Author Comment

by:pieman8080
ID: 18056238
perfect, thank u very much
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux , how do I append to the PATH and not mess up the existing PATH 4 70
Openwrt vnstat 9 183
Problem to run file 9 112
busybox bash/ash - bash -x | grep 19 139
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now