Sponsored Content
Top Forums Shell Programming and Scripting How to Sort by Date and Time? Post 302722599 by Don Cragun on Saturday 27th of October 2012 07:47:49 PM
Old 10-27-2012
Note that if you want to sort by date and time, with the data you have the following sort command will work:
Code:
sort -k1.7,1 -k1.4,1.5 -k1.1,1.2 -k2,2 input

Note that this sort uses the default whitespace field delimiter, instead of a period because the time stamps aren't delimited by a period. Note also that since your data has fixed-wdith date and time fields with leading zeros, you can use either an alphanumeric sort or a numeric sort for the date fields. Using an alphanumeric sort for the time stamp allows us to use one key-k2,2instead of three keys-k2.1,2.2 -k2.4,2.5 -k2.7,2.8 to sort the time. (A numeric sort-k2n,2would only sort on the hour since ":" is not a numeric character.)
The sort keys (in order) are from the 7th character in the 1st field to the end of the 1st field (year), from the 4th character through the 5th character in the 1st field (month), from the 1st character through the 2nd character in the 1st field (day), and from the start of the 2nd field to the end of the 2nd field (time).

Since your sample input data only had one time stamp per day, I tested the above command using the following input (which duplicates the input you provided but changes the date stamps on the 2nd occurrence of each entry to verify that differences in hours, minutes, and seconds all sort correctly:
Code:
input:
08.05.2012 10:52:32 User: xxxx
15.05.2012 11:30:38 User: xxxx
22.05.2012 11:56:39 User: xxxx
29.05.2012 16:33:04 User: xxxx
19.06.2012 10:51:55 User: xxxx
26.06.2012 11:04:27 User: xxxx
12.06.2012 14:40:27 User: xxxx
05.06.2012 20:46:18 User: xxxx
18.07.2012 03:13:16 User: xxxx
08.05.2012 11:52:32 User: xxxx
15.05.2012 10:30:38 User: xxxx
22.05.2012 11:57:39 User: xxxx
29.05.2012 16:32:04 User: xxxx
19.06.2012 10:50:55 User: xxxx
26.06.2012 11:05:27 User: xxxx
12.06.2012 14:40:28 User: xxxx
05.06.2012 20:46:17 User: xxxx
18.07.2012 01:23:45 User: xxxx

output:
08.05.2012 10:52:32 User: xxxx
08.05.2012 11:52:32 User: xxxx
15.05.2012 10:30:38 User: xxxx
15.05.2012 11:30:38 User: xxxx
22.05.2012 11:56:39 User: xxxx
22.05.2012 11:57:39 User: xxxx
29.05.2012 16:32:04 User: xxxx
29.05.2012 16:33:04 User: xxxx
05.06.2012 20:46:17 User: xxxx
05.06.2012 20:46:18 User: xxxx
12.06.2012 14:40:27 User: xxxx
12.06.2012 14:40:28 User: xxxx
19.06.2012 10:50:55 User: xxxx
19.06.2012 10:51:55 User: xxxx
26.06.2012 11:04:27 User: xxxx
26.06.2012 11:05:27 User: xxxx
18.07.2012 01:23:45 User: xxxx
18.07.2012 03:13:16 User: xxxx

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort By Date and Time

Hi , I would like to list or sort by date and time (the files are named in day and time format) where the latest file will be placed at the bottom and the earliest file be placed at the top. Can anybody help me? My files are named in the following manner. EG: abc_071128_144121_data "... (21 Replies)
Discussion started by: Raynon
21 Replies

2. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

Hi guys, I know that this topic has been discuss numerous times, and I have search the net and this forum for it. However, non able to address the problem I faced so far. I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Discussion started by: DrivesMeCrazy
5 Replies

3. Shell Programming and Scripting

shell script to sort entries in a file by date and time

Hello All, Need a shell script to sort entries in a file by date and time. Below are the entries in the file, i need to sort it first by the date and then time Note :- Date is in MM/DD/YY format and date comes as the 6th & time comes on 7th coloumns respectively. 150 pbnawldb001-b... (10 Replies)
Discussion started by: ajiwww
10 Replies

4. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

5. Solaris

modifying date and time and time zone on solaris 5.10 with (redundant server) veritas

I have a cluster of two Solaris server (veritas cluster). one working and the other is standby I am going to change the date on them , and am looking for a secure solution as it is giving an important service. my opinion is that the active one doesn't need to be restarted (if I don't change the... (1 Reply)
Discussion started by: barry1946
1 Replies

6. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

7. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

8. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

9. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

10. Shell Programming and Scripting

Sort date time in ascending order

Hi, i had a data block (coming from pipe from other codes) as: H YF_CO.dat 77164 11/17/2013 04:00:02 731374590.96 1 1 731374590.96 76586 77164 578 2988 Y H YF_CO.dat 77164 11/17/2013 04:00:07 731374590.96 1 4 731374590.96 76586 77164 578 2988 Y H YF_CO.dat 77178 ... (5 Replies)
Discussion started by: pr5439
5 Replies
AGR(4)							   BSD Kernel Interfaces Manual 						    AGR(4)

NAME
agr -- link aggregation pseudo network interface driver SYNOPSIS
pseudo-device agr DESCRIPTION
The agr driver provides link aggregation functionality (a.k.a. L2 trunking or bonding). It supports the IEEE 802.3ad Link Aggregation Control Protocol (LACP) and the Marker Protocol. The agr driver supports the following link specific flags for ifconfig(8): link0 Use the round-robin distribution algorithm. Don't use it unless you're really sure, because it violates the frame ordering rule. -link0 Use the default distribution algorithm, which is based on the hash of DA/SA, TCI, and, if available, some upper layer protocol infor- mation like ip(4) DA/SA. link1 Disable LACP. Prevents any LACP or Marker messaging which leaves the ports in the default static configuration. Set this prior to adding ports. EXAMPLES
Create an agr interface, agr0, and attach re0 and re1 to it. In other words, aggregate re0 and re1 so that they can be used as a single interface, agr0. The physical interfaces which are attached to the agr interface must not have any IP addresses, neither IPv4 nor IPv6. ifconfig re0 inet xxx.xxx.xxx.xxx delete ifconfig re0 inet6 fe80::xxxx:xxxx:xxxx:xxxx delete ifconfig re1 inet xxx.xxx.xxx.xxx delete ifconfig re1 inet6 fe80::xxxx:xxxx:xxxx:xxxx delete ifconfig agr0 create ifconfig agr0 agrport re0 ifconfig agr0 agrport re1 Destroy an interface created in the above example. ifconfig agr0 -agrport re0 ifconfig agr0 -agrport re1 ifconfig agr0 destroy SEE ALSO
ifconfig(8) STANDARDS
IEEE 802.3ad Aggregation of Multiple Link Segments HISTORY
The agr driver first appeared in NetBSD 4.0. AUTHORS
The agr driver was written by YAMAMOTO Takashi. BUGS
There is no way to configure LACP administrative variables, including system and port priorities. The current implementation of the agr driver always performs active-mode LACP and uses 0x8000 as system and port priorities. The agr driver uses the MAC address of the first-added physical interface as the MAC address of the agr interface itself. Thus, removing the physical interface and using it for another purpose can result in non-unique MAC addresses. The current implementation of the agr driver doesn't prevent unsafe operations like some ioctls against underlying physical interfaces. Such operations can result in unexpected behaviors, and are strongly discouraged. There is no way to configure agr interfaces without attaching physical interfaces. Physical interfaces being added to the agr interface shouldn't have any addresses except for link level address. Otherwise, the attempt will fail with EBUSY. Note that it includes an automatically assigned IPv6 link-local address. BSD
February 23, 2010 BSD
All times are GMT -4. The time now is 10:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy