How to sort grep result based on timestamp?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to sort grep result based on timestamp?
# 1  
Old 09-10-2013
How to sort grep result based on timestamp?

Hi,

Trying to sort grep result based on timestamp of the filename.
I have the following result and want to sort them on timestamp
Code:
grep -i  'ERROR' *log*2013*[0-9]
s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier [SQ_xxxxxxxxxx#]. Total errors [0]
s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:MAPPING> TM_6018 The session completed with [0] row transformation errors.
s_m_yyy_yyy_yyy_yyy_yyy_yyy_yyy.log.20130909131721:DIRECTOR> TM_6708 Using configuration property [ConnectionErrorCodesFile,/informatica/dev/pc901/server/bin/connect_errors.act]
s_m_yyy_yyy_yyy_yyy_yyy_yyy_yyy.log.20130909131721:MAPPING> TM_6307 DTM error log disabled.
s_m_zzz_zzz_zzz_zzzzzz.log.20130827072827:DIRECTOR> TM_6708 Using configuration property [ConnectionErrorCodesFile,/informatica/dev/pc901/server/bin/connect_errors.act]
s_m_zzz_zzz_zzz_zzzzzz.log.20130827072827:MAPPING> TM_6307 DTM error log disabled.
s_m_zzz_zzz_zzz_zzzzzz.log.20130827072827:MAPPING> MQ_29004 Filter parse error: Line 1, column 4: Left operand must be boolean

Thanks in Advance for your time and help
# 2  
Old 09-10-2013
Well they're in YYYYMMDD order already which is convenient.

We tell it to split fields on . then sort on characters 1 through 15 of the third field.

Code:
sort -t. -k 3.1,3.15 < infile > outfile

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 09-10-2013
Hello,
sort list file before or after grep ?

Regard.
# 4  
Old 09-10-2013
It'll work either way, but it'd be much less work to sort after -- less data to sort.
# 5  
Old 09-10-2013
@disedorgue

Want to sort the result of grep
# 6  
Old 09-10-2013
@Corona688 - Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Find files and sort by timestamp

Used below command to get list of files sorted by timestamp find -L . -type f -name '*dat*' | xargs ls -ltrg I want to get only the filenames so I tried adding basename but it doenst work , can some one advise on how to get only file name (1 Reply)
Discussion started by: lalitpct
1 Replies

3. Shell Programming and Scripting

Sort Unique Column with the most recent timestamp

Hello, I have a sample file with the below contents : Backup Oracle8_P112_PEGA_Archivedel Completed full 10/11/2015 03:50:06PM Backup Oracle8_G567_PEGA_Archivedel Completed full 10/11/2015 01:15:56PM Backup Oracle8_P112_PEGA_Archivedel Completed full ... (8 Replies)
Discussion started by: rahul2662
8 Replies

4. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

5. Shell Programming and Scripting

Output block of lines in a file based on grep result

Hi I would appreciate your help with this. I have a output file from a command. It is broken based on initial of the users. Exmaple of iitials MN & SS. Under each section there is information pertaining to the user however each section can have different number of lines. MY challenge is to ... (5 Replies)
Discussion started by: mnassiri
5 Replies

6. Programming

Sort the files on their name and then the timestamp using Perl

Hi All, I am new to Perl. I have a scenario to code. In a folder I have number of files and they will start with P01 or P02 or P03 and so on..I have to sort them on name first and then on time stamp. Ex. File name timestamp P01_file1.txt 1PM P02_file1.txt 1AM P01_file2.txt 2PM... (12 Replies)
Discussion started by: unankix
12 Replies

7. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

8. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

9. Shell Programming and Scripting

sort for timestamp information-YYYY-MM-DD HH:MM:SS

Dear all, Please advice how do I sort a file based on timestamp information. I want to sort the second column in asc/desc order which has timestamp information in format YYYY-MM-DD HH:MM:SS Example File - Input.txt contains cat ss.txt 100|2009-03-30 11:38:43 141|2009-06-01 12:12:01... (1 Reply)
Discussion started by: sureshg_sampat
1 Replies
Login or Register to Ask a Question