- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sort or awk?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:30 AM
04-02-2002 02:30 AM
Calling all awk gurus! I am trying to sort a group of files by date order... using the following:
ls -la |sort -r -k 6
This sort the list by field 6 (the month) but it sort it alphabetically... is there anyway to sort this using the calender format? so as this is reverse, I'm hoping for:
Dec
Dec
Mar
Jan
etc... etc...
thanks.
Nik
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:34 AM
04-02-2002 02:34 AM
Re: sort or awk?
Use -t flag of ls
ls -t ... or ls -rt ( for reverse order)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:34 AM
04-02-2002 02:34 AM
Re: sort or awk?
"ls -lt" or "ls -lrt", depending on whether you want ascending or descending order.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:41 AM
04-02-2002 02:41 AM
Re: sort or awk?
of course, you're all correct... have 10 points each for taking the time to answer my question! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:57 AM
04-02-2002 02:57 AM
Re: sort or awk?
What I'm trying to do is a find command to find the 10 most recent documents within a directory (and all subs). So I'm using the find command with -mtime and then sending all output that it finds, to a temporary file.. which I would then like to sort by month (field 6) not alphabetically but by calender... any ideas again!? potential for even more points now! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 03:20 AM
04-02-2002 03:20 AM
Re: sort or awk?
Try this:
find . -type d -exec ls -lrt {} \;
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 03:24 AM
04-02-2002 03:24 AM
Re: sort or awk?
Or try this if you want only the first 10 occurrence:
for i in `find . -type d -print
do
ls -lrt $i | head -10
done
Regards,
Justo.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 03:53 AM
04-02-2002 03:53 AM
Re: sort or awk?
#!/usr/bin/perl -w
use strict;
use File::Find;
my @dir = (".");
my @files;
find (sub {
-M $_ < 0.9 and return; # Too new
-M _ > 6.4 and return; # Too old
push @files, $File::Find::name;
}, @dir);
my @sorted_by_date = sort { -M $a <=> -M $b } @files;
print "Newest 5: @sorted_by_date[0..4]\n";
print "Oldest 5: @sorted_by_date[-5..-1]\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 04:38 AM
04-02-2002 04:38 AM
Re: sort or awk?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 04:49 AM
04-02-2002 04:49 AM
Re: sort or awk?
find . -type d -xdev | xargs ll -ltr > /tmp/file1
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 04:53 AM
04-02-2002 04:53 AM
Re: sort or awk?
Are you trying to say you want the MONTH's sorted in reverse, like this:
SEP
OCT
NOV
MAY
MAR
JUN
JUL
JAN
FEB
DEC
AUG
APR
which is what an APLHA sort will do??????????
Which I don't think you want. What you really need to do is look at procura's perl example and modify it for what you want.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 04:56 AM
04-02-2002 04:56 AM
Re: sort or awk?
No I'm trying to work out how to get them sorted like...
Dec
Nov
Oct
Sep
Aug
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 06:02 AM
04-02-2002 06:02 AM
Re: sort or awk?
@dir = ("/tmp", "/etc", "/usr/sbin");
or
@dir = qw( /tmp/blah /tmp/foo/ahhrg /stand /usr/etc );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 07:52 AM
04-02-2002 07:52 AM
Re: sort or awk?
#!/usr/local/bin/perl
#
# written by harry d brown jr
#
# get the "option"
#
$opts = $ARGV[0];
#
if ( ( $#ARGV < 0 ) || ( $opts !~ /-atime|-ctime|-mtime/ ) ) {
print "Usage : ./o [-atime|-ctime|-mtime] [dirpath ...]\n";
exit 1;
}
#
# get directories to list
#
$DIRS2list = "";
for ( $i=1 ; $i le $#ARGV ; $i++ ) {
$DIRS2list .= $ARGV[$i] . " ";
}
#
# find the files, and not we are only using real files, to use all
# remove the "-type f"
#
open(FILELIST,"find $DIRS2list -type f|");
#
$filemat="";
#
# a little trickery to get the optins and LS commands
#
$LSOPTS = "u c";
$OPTSTR = "amc";
$DATEIDX = index($OPTSTR,substr($opts,1,1));
$DATECHAR = substr($LSOPTS,$DATEIDX,1);
#
# read the file list from find
#
while (
chop;
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$
blocks) = stat $_;
$DATEFIELD[0] = $atime;
$DATEFIELD[1] = $mtime;
$DATEFIELD[2] = $ctime;
$date2use = $DATEFIELD[$DATEIDX];
push @filemat,$date2use . " " . $_;
}
#
# sort the array on the time the user choose
#
#
@newmat = sort { $b <=> $a } @filemat;
#
# spit the listing out
#
foreach $filestuff ( @newmat ) {
($filetime,$filename) = split(/ /,$filestuff);
print `ls -l$DATECHAR $filename`;
}
# end of script
You might have to change the PATH to perl, and the options are this:
./prog -atime /tmp /var/tmp /whatever
-atime = last access time
-mtime = last file change
-ctime = last INODE change
use a "." (period) for the current directory.
procura, what do ya think?
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 12:34 PM
04-02-2002 12:34 PM
Re: sort or awk?
If you still want the find command to do what you are looking for, then here it is:
ls -lt `find . -mtime +10 -type f -print`
This will find all files older than 10 days from current date and will sort in the order that you need ...
Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 12:56 PM
04-02-2002 12:56 PM
Re: sort or awk?
I forgot to mention one more thing ... there is a catch ... if this doesn't find any files older than 10 days then it would list everything in the current directory or from wherever you are executing it ...
-Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2002 02:21 PM
04-02-2002 02:21 PM
Re: sort or awk?
Hi Nik:
'sort' will serve quite well for your purpose. You simply need to describe the sort key with the '-M' option to cause the order of the month names to be compared such that JAN < FEB < ... < DEC.
Have a look at the man pages for 'sort'.
Regards!
...JRF...