- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sort options? easy 10 points!
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
Discussions
Discussions
Forums
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
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
тАО09-03-2006 06:08 AM
тАО09-03-2006 06:08 AM
Here are 10 easy points for you. Can you tell me the sort options I need to use to sort German dates?
Sort these 3 lines:
01.10.2006 x
01.11.2005 y
01.09.2006 z
Result must look like:
01.11.2005 y
01.09.2006 z
01.10.2006 x
Solution must work for (presumably using the sort command with options that work) SuSE Linux Professional 9.3.
The first 3 answers that I can confirm will work for SuSE 9.3 will get 10 points each.
Thanks! Christian
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2006 12:36 PM
тАО09-03-2006 12:36 PM
SolutionI Just learnt something. try sort with a few switches:
sort -k1.7,1.11 -k1.4,1.5 -k1.1,1.2 file1 file2
-k sorts on fields
1 is field 1 or the date, (y,z,x) would be field 2.
7 - 11 is YYYY
4 - 5 is MM
1 - 2 is DD
Seems to work including adding exra data to prove the test. Works on RHEL4 and even works on Tru64!
Robert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2006 04:21 PM
тАО09-03-2006 04:21 PM
Re: sort options? easy 10 points!
1. Create a file named file1 contain 3 lines as below.
01.10.2006 x
01.11.2005 y
01.09.2006 z
2. # sort -k 1.7,1.10 file1 (sort by seventh to tenth characters of field one)
3. Result,
01.11.2005 y
01.09.2006 z
01.10.2006 x
regards,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-03-2006 04:59 PM
тАО09-03-2006 04:59 PM
Re: sort options? easy 10 points!
I agree with the solution provided by Robert Walker. It sort by 7th to 10th characters of first field, then 4th to 5th characters of first field, follow by 1st to 2nd characters of first field. It will works on any combination of contents.
I already tested on Suse 9.3, it works.
regards,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 02:14 AM
тАО09-06-2006 02:14 AM
Re: sort options? easy 10 points!
if you abored with the straight forward solutions:
tr " " "." < b.lis | sort -t'.' -k3,3 -k2,2 -k1 | sed 's/./ /11'
Using the date separator as a field seperator.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-13-2006 04:57 AM
тАО09-13-2006 04:57 AM
Re: sort options? easy 10 points!
sort -n -t'.' -k3 -k2 -k1
I had the additional difficulty of the fields being different lengths e.g. 9 for September and 10 for October so I had to use -n also
Thanks again all of you that was a great help!