Sponsored Content
Top Forums Shell Programming and Scripting sort file text by date as a "ls -t" Post 302358614 by protocomm on Saturday 3rd of October 2009 12:50:21 PM
Old 10-03-2009
sort file text by date as a "ls -t"

I have, a file wich list file on server ftp and i want to sort the file text as the command "ls -t"

i.e
Code:
drwxr-x---  2 ftp_mont System            0 Sep 30 09:16 .
drwxr-x---  2 ftp_mont System            0 Jul 15  2009 ..
-rwxr-x---  1 ftp_mont System    343998791 Sep 01 09:20 manif laitiers-H264.mov
-rwxr-x---  1 ftp_mont System     12063097 Sep 27 15:32 Mende_Mende_ITW.mov
-rwxr-x---  1 ftp_mont System       918234 Jun 27 15:44 Mende_Mende_COMJUN.m4a
-rwxr-x---  1 ftp_mont System       918234 Jan 22 15:44 Mende_Mende_COMJAN.m4a
-rwxr-x---  1 ftp_mont System       918234 Jan 20 15:44 Mende_Mende_COMJUN.m4a
-rwxr-x---  1 ftp_mont System       918234 Jan 22 16:44 Mende_Mende_COMJUN.m4a
-rwxr-x---  1 ftp_mont System       918234 Oct 27 15:44 Mende_Mende_COMOCT.m4a
-rwxr-x---  1 ftp_mont System       918234 Sep 27 15:44 Mende_Mende_COM.m4a
-rwxr-x---  1 ftp_mont System    250324761 Sep 27 15:47 Dossier_secheresse-H264-1.mov
-rwxr-x---  1 ftp_mont System    169097455 Sep 27 15:55 Mende_Mende-H264.mov
-rwxr-x---  1 ftp_mont System    343998791 Sep 30 09:20 manif laitiers-H264.mov
-rwxr-x---  1 ftp_mont System    343998791 Sep 30 10:20 manif laitiers1-H264.mov
-rwxr-x---  1 ftp_mont System    343998791 Sep 31 09:20 manif laitiers2-H264.mov

I have imagined this code, but i think there are much more simple code...

Code:
cat /Users/macbook/Desktop/test | sed '1,2'd | sort -t : -k 1,2 | sort -t : -k 2,2 | sort -k 7 |  awk '{if($6=="Jan")a[NR]=$0}
{if($6=="Feb")b[NR]=$0}
{if($6=="Mar")c[NR]=$0}
{if($6=="Apr")d[NR]=$0}
{if($6=="May")e[NR]=$0}
{if($6=="Jun")f[NR]=$0}
{if($6=="Jul")g[NR]=$0}
{if($6=="Aug")h[NR]=$0}
{if($6=="Sep")j[NR]=$0}
{if($6=="Oct")k[NR]=$0}
{if($6=="Nov")l[NR]=$0}
{if($6=="Dec")m[NR]=$0}
END{
for(i=1;i<=length(a);i++){print a[i]};
for(i=1;i<=length(b);i++){print b[i]};
for(i=1;i<=length(c);i++){print c[i]};
for(i=1;i<=length(d);i++){print d[i]};
for(i=1;i<=length(e);i++){print e[i]};
for(i=1;i<=length(f);i++){print f[i]};
for(i=1;i<=length(g);i++){print g[i]};
for(i=1;i<=length(h);i++){print h[i]};
for(i=1;i<=length(j);i++){print j[i]};
for(i=1;i<=length(k);i++){print k[i]};
for(i=1;i<=length(l);i++){print l[i]};
for(i=1;i<=length(m);i++){print m[i]}
}' | awk 'NF{print $9,$10,$11,$12,$13,$14,$15}' | awk '{a[NR]=$0}END{for(i=FNR;i>=0;i--){print a[i]}}'

Thanx.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

2. Solaris

"mail" command sort by date

Hello experts, I am using SunFire T200. When I start reading the mail with "mail" command it comes older mail first. From MAILER-DAEMON Sat Mar 28 06:02:48 2009 Return-Path: <MAILER-DAEMON@emarn1> Received: from localhost (localhost) .... .... I want to see the most recent mail... (1 Reply)
Discussion started by: thepurple
1 Replies

3. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

4. Shell Programming and Scripting

Meaning of "b" modifier in "sort" command

I need to sort the following file by the rhdiskpower devices in the last column: Total_MB Free_MB OS_MB Name Failgroup Library Label UDID Product Redund Path 1024 851 1024 OCRVOT1_0000 OCRVOT1_0000 System UNKNOWN ... (3 Replies)
Discussion started by: wjssj
3 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

sort text having delimiter with "|" (pipe)

i am having text file below NARGU S S 12358 SALES REP |22| Acccount/s RAJU R B 64253 SALES REP |12| Acccount/s RUKMAN S 32588 SALES REP |10| Acccount/s NARGUND S S 12356... (3 Replies)
Discussion started by: suryanarayana
3 Replies

7. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

8. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

9. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
GZEXE(1)						      General Commands Manual							  GZEXE(1)

NAME
gzexe - compress executable files in place SYNOPSIS
gzexe name ... DESCRIPTION
The gzexe utility allows you to compress executables in place and have them automatically uncompress and execute when you run them (at a penalty in performance). For example if you execute ``gzexe /usr/bin/gdb'' it will create the following two files: -rwxr-xr-x 1 root root 1026675 Jun 7 13:53 /usr/bin/gdb -rwxr-xr-x 1 root root 2304524 May 30 13:02 /usr/bin/gdb~ /usr/bin/gdb~ is the original file and /usr/bin/gdb is the self-uncompressing executable file. You can remove /usr/bin/gdb~ once you are sure that /usr/bin/gdb works properly. This utility is most useful on systems with very small disks. OPTIONS
-d Decompress the given executables instead of compressing them. SEE ALSO
gzip(1), znew(1), zmore(1), zcmp(1), zforce(1) CAVEATS
The compressed executable is a shell script. This may create some security holes. In particular, the compressed executable relies on the PATH environment variable to find gzip and some standard utilities (basename, chmod, ln, mkdir, mktemp, rm, sleep, and tail). BUGS
gzexe attempts to retain the original file attributes on the compressed executable, but you may have to fix them manually in some cases, using chmod or chown. GZEXE(1)
All times are GMT -4. The time now is 10:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy