- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sorting date
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
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
08-16-2007 06:23 AM
08-16-2007 06:23 AM
sorting date
07/23 testserver /test/trees/oradb02 29%
07/24 testserver /test/trees/oradb02 29%
07/25 testserver /test/trees/oradb02 28%
07/26 testserver /test/trees/oradb02 29%
07/27 testserver /test/trees/oradb02 29%
07/28 testserver /test/trees/oradb02 29%
07/29 testserver /test/trees/oradb02 33%
07/30 testserver /test/trees/oradb02 29%
07/31 testserver /test/trees/oradb02 30%
08/1 testserver /test/trees/oradb02 30%
08/2 testserver /test/trees/oradb02 30%
08/3 testserver /test/trees/oradb02 32%
08/4 testserver /test/trees/oradb02 32%
08/5 testserver /test/trees/oradb02 36%
08/6 testserver /test/trees/oradb02 32%
08/7 testserver /test/trees/oradb02 36%
08/8 testserver /test/trees/oradb02 32%
08/9 testserver /test/trees/oradb02 37%
08/10 testserver /test/trees/oradb02 33%
08/11 testserver /test/trees/oradb02 33%
08/12 testserver /test/trees/oradb02 32%
08/13 testserver /test/trees/oradb02 31%
08/14 testserver /test/trees/oradb02 36%
08/15 testserver /test/trees/oradb02 36%
08/16 testserver /test/trees/oradb02 36%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 07:01 AM
08-16-2007 07:01 AM
Re: sorting date
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 07:19 AM
08-16-2007 07:19 AM
Re: sorting date
What you could do is grep the current month and then sort, then re-grep the previous and sort and append, etc...etc...
grep ^`date +%m` somefile |sort -n
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 07:30 AM
08-16-2007 07:30 AM
Re: sorting date
--------------------------------------------
#!/usr/bin/sh
typeset -i STAT=0
typeset MO=$(date '+%m') # current month
awk -v month=${MO} \
'{ split($1,a,"/"); if ((a[1] + 0) == (month + 0)) {printf("%02d %02d ",a[1],a[2]); print $0; }}' | \
sort | \
awk '{for (i = 3; i <= (NF - 1); ++i) {printf("%s ",$i); print $NF}'
STAT=${?}
exit ${STAT}
--------------------------------------------
The logic looks right and the syntax should be ok. The stuff abount (month + 0) is correct though it appears strange; it forces the evaluation into numerical context rather than string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 07:42 AM
08-16-2007 07:42 AM
Re: sorting date
Use SED or any tool you like. In perl I'd use:
$perl -pe 's#/(\d\s)#/0${1}#' bad > good
or with in-place editing:
$ perl -i.old -pe 's#/(\d\s)#/0${1}#' mydata
Of course you can sort with perl also. For example:
$ $ perl -ne '$data{$.}=$_;($m,$d)=split /[\/ ]/;$date{$.}=100*$m+$d}{foreach (sort {$date{$a}<=>$date{$b}} keys %date) {print $data{$_}}' y.txt
or
$ $ perl -e 'sub d {($m,$d)=split /[\/ ]/; return $m+100+$d} print sort {d($a)<=>d{$b}} <>' y.txt
The first solution load two arrays indexed by a line number, one with each data line and one with the data recalculated to be month times 100 + day. The sort the date array by value and print.
The next solution defines a function 'd' which gets that 100*M + D as return value for each record. Now print all input through a sort function comparing the 'd' function value for each input line.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 08:12 AM
08-16-2007 08:12 AM
Re: sorting date
# grep $(date +%m) infile | sort -k1,1.2n -k1.4,1n
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 08:21 AM
08-16-2007 08:21 AM
Re: sorting date
my.sh < infile > outfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 08:52 AM
08-16-2007 08:52 AM
Re: sorting date
Similar to Sandman's reply, you could leverage the "/" as a field delimiter and do:
# sort -t/ -k1n -k2n file.in > file.out
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2007 08:59 AM
08-16-2007 08:59 AM
Re: sorting date
I concur with Sandman! that it would be good to see suggested sample output. For example it's not clear to me that if say it is the second of the month, should the result be just 2 lines?
Hein.