Sponsored Content
Top Forums Shell Programming and Scripting How to Sort files on date field Post 302258909 by Perderabo on Sunday 16th of November 2008 12:56:46 PM
Old 11-16-2008
Code:
$ cat data
SONYELEC00.GI22973.01May07_1623.gpg
SONYELEC00.GI22973.06Mar08_1504.gpg
SONYELEC00.GI22973.06Sep07_1900.gpg
SONYELEC00.GI22973.08Nov07_1900.gpg
SONYELEC00.GI22973.13Aug07_1900.gpg
SONYELEC00.GI22973.19Apr07_1733.gpg
SONYELEC00.GI22973.22Jan08_1900.gpg
SONYELEC00.GI22973.24Apr07_1757.gpg
SONYELEC00.GI22973.26Jun08_1900.gpg
SONYELEC00.GI22974.01May07_1623.gpg
SONYELEC00.GI22974.13Aug07_1900.gpg
SONYELEC00.GI22974.19Apr07_1733.gpg
SONYELEC00.GI22974.24Apr07_1757.gpg
$
$ cat sorta
#! /usr/bin/ksh
Jan=01 Feb=02 Mar=03 Apr=04 May=05 Jun=06
Jul=07 Aug=08 Sep=09 Oct=10 Nov=11 Dec=12

while read name ; do
        base=${name%.gpg}
        hhmm=${base##*_}
        base=${base%_*}
        date=${base##*.}
        day=${date%?????}
        year=${date#?????}
        year=20${year}
        month=${date#??}
        month=${month%??}
        eval month=\$$month
        sort="${year}${month}${day}${hhmm}"
        echo $sort $name
done | sort | while read junk name ; do
        echo $name
done
exit 0
$
$
$ ./sorta < data
SONYELEC00.GI22973.19Apr07_1733.gpg
SONYELEC00.GI22974.19Apr07_1733.gpg
SONYELEC00.GI22973.24Apr07_1757.gpg
SONYELEC00.GI22974.24Apr07_1757.gpg
SONYELEC00.GI22973.01May07_1623.gpg
SONYELEC00.GI22974.01May07_1623.gpg
SONYELEC00.GI22973.13Aug07_1900.gpg
SONYELEC00.GI22974.13Aug07_1900.gpg
SONYELEC00.GI22973.06Sep07_1900.gpg
SONYELEC00.GI22973.08Nov07_1900.gpg
SONYELEC00.GI22973.22Jan08_1900.gpg
SONYELEC00.GI22973.06Mar08_1504.gpg
SONYELEC00.GI22973.26Jun08_1900.gpg
$

 

10 More Discussions You Might Find Interesting

1. Linux

sort files by date

Hi All, Sorry to throw this frequent question but I lost my notes on it. How do you list the files by date? I'm on red hat. Thanks in advance, itik (1 Reply)
Discussion started by: itik
1 Replies

2. Shell Programming and Scripting

How to sort a field in a file having date values

Hi All, I am having a pipe delimited file .In this file the 3rd column is having date values.I need to get the min date and max date from that file. I have used cut -d '|' test.dat -f 3|sort -u But it is not sorting the date .How to sort the date column using unix commands Thanks ... (4 Replies)
Discussion started by: risshanth
4 Replies

3. UNIX for Dummies Questions & Answers

Sort files by date, not showing files from today

Hi all, i'm new here in this forum. I really like the helpful answers in this forum. Here a short question. For a script i have to sort files by date and exclude the files of the actual date. Sorting the files by date and preparing the output for awk is done by this line: ls -l... (3 Replies)
Discussion started by: carlosdivega
3 Replies

4. Shell Programming and Scripting

How to sort a set of files by date in a directory?

hi there, I have a directory which contents I can parse dynamically. I end up with a file list. I then want to display those files sorted by date, oldest files first. I have very very little PERL experience...Would anyone know how to do that ? Thanks in advance. (8 Replies)
Discussion started by: alexf
8 Replies

5. Shell Programming and Scripting

Sort two columns in a field, one of them being a date

Hi, I have a set of columns in a csv file, my first row being an integer and 2nd being a date. I want to first sort it using the first column and then by the second. for e.g. i have , 1234,09/05/2009,hi 5678,01/01/2008,hi 1234,11/03/2006,hello 5678,28/07/2010,hello i tried this... (5 Replies)
Discussion started by: sweta_doshi
5 Replies

6. UNIX for Dummies Questions & Answers

Sort field by date mm/dd/yyyy

Hello Group, I would like to sort the below file by date (first year then month and day) and I used the following command but it does not work sort -n -t"/" -k3 -k1 -k2 "sample original file" 12/28/2009,1.0353 12/31/2009,1.0357 12/30/2009,1.0364 12/29/2009,1.0366 12/24/2009,1.0386... (6 Replies)
Discussion started by: csierra
6 Replies

7. Shell Programming and Scripting

Sort files by date in filename

Hi, I am a newbie to shell programming and I need some help in sorting a list of files in ascending order of date in the filenames. The file format is always : IGL01_AC_D_<YYYYMMDD>_N01_01 For example, in a directory MyDirectory I have the following files: IGL01_AC_D_20110712_N01_01.dat... (11 Replies)
Discussion started by: Yuggy
11 Replies

8. Shell Programming and Scripting

Sorting Date Field with Sort -k :/

SOLVED : (17 Replies)
Discussion started by: Glitch100
17 Replies

9. UNIX for Dummies Questions & Answers

How to sort the 6th field of tab delimited files?

Here's a sample of the data: NAME BIRTHDAY SEX LOCATION AGE ID Jim 05/11/1986 M Japan 27 86 Rei 08/25/1990 F Korea 24 33 Jane 02/24/1985 F India 29 78 I've been trying to sort files using the... (8 Replies)
Discussion started by: maihani
8 Replies

10. AIX

Sort by date field in AIX

I wanted to sort the below data on 4th field(comma seperator) based on month and date and time on AIX OS. Input data: 3,AJ,30 Jul 06:30,30 Jul 06:30 5,AJ,30 Jul 06:30,30 Jul 06:49 10,AJ,30 Jul 06:30,02 Jan 05:41 4,AJ,30 Jul 06:30,30 Jul 06:36 2,AJ,30 Jul 06:30,28 Jul 06:45 9,AJ,30 Jul... (2 Replies)
Discussion started by: Amit Joshi
2 Replies
GPG-PRESET-PASSPHRASE(1)					 GNU Privacy Guard					  GPG-PRESET-PASSPHRASE(1)

NAME
gpg-preset-passphrase - Put a passphrase into gpg-agent's cache SYNOPSIS
gpg-preset-passphrase [options] [command] cache-id DESCRIPTION
The gpg-preset-passphrase is a utility to seed the internal cache of a running gpg-agent with passphrases. It is mainly useful for unat- tended machines, where the usual pinentry tool may not be used and the passphrases for the to be used keys are given at machine startup. Passphrases set with this utility don't expire unless the --forget option is used to explicitly clear them from the cache --- or gpg-agent is either restarted or reloaded (by sending a SIGHUP to it). It is necessary to allow this passphrase presetting by starting gpg-agent with the --allow-preset-passphrase. gpg-preset-passphrase is invoked this way: gpg-preset-passphrase [options] [command] cacheid cacheid is either a 40 character keygrip of hexadecimal characters identifying the key for which the passphrase should be set or cleared. The keygrip is listed along with the key when running the command: gpgsm --dump-secret-keys. Alternatively an arbitrary string may be used to identify a passphrase; it is suggested that such a string is prefixed with the name of the application (e.g foo:12346). One of the following command options must be given: --preset Preset a passphrase. This is what you usually will use. gpg-preset-passphrase will then read the passphrase from stdin. --forget Flush the passphrase for the given cache ID from the cache. The following additional options may be used: -v --verbose Output additional information while running. -P string --passphrase string Instead of reading the passphrase from stdin, use the supplied string as passphrase. Note that this makes the passphrase visible for other users. SEE ALSO
gpg(1), gpgsm(1), gpg-agent(1), scdaemon(1) The full documentation for this tool is maintained as a Texinfo manual. If GnuPG and the info program are properly installed at your site, the command info gnupg should give you access to the complete manual including a menu structure and an index. GnuPG 2.0.15 2010-07-05 GPG-PRESET-PASSPHRASE(1)
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy