Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help sorting a text file

Posted on 2006-12-01
5
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

730 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