- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Sorting a list by a field
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
02-16-2007 05:06 AM
02-16-2007 05:06 AM
Re: Sorting a list by a field
>xxx xxx xxx xxx xxx xxx xxxx 02/02/07
>So they don't sort right.
>The only thing that I do know is that it's always the last field. I cannot think how >to make awk or sort work on this.
Try the shell script below if your issue has not been resolved yet. The script below takes the input file ($1) as its only argument and ends up modifying it with the lines sorted chronologically. Invoke as follows:
# ./sortdate.sh inputfile
=======================sortdate.sh=======================
#!/usr/bin/sh
awk '{split($NF,z,"/");l=z[3]""z[2]""z[1];print l,$0}' $1 | sort -nk1,1 |
awk '{for(i=2;i<=NF;++i) printf(i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2007 06:35 AM
02-16-2007 06:35 AM
Re: Sorting a list by a field
=======================sortdate.sh=======================
#!/usr/bin/sh
awk '{split($NF,z,"/");l=z[3]""z[1]""z[2];print l,$0}' $1 | sort -nk1,1 |
awk '{for(i=2;i<=NF;++i) printf(i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2007 11:27 AM
02-21-2007 11:27 AM
Re: Sorting a list by a field
Marlou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2007 09:02 AM
03-29-2007 09:02 AM
Re: Sorting a list by a field
On a different note, why doesn't the following sort the file by the last 2 numeric characters?
# cat file
bd0hbsv1 CNAME expconserv2-port20
bd0hbsv2 CNAME expconserv2-port09
bd0hbsv3 CNAME expconserv2-port11
bd0ints2 CNAME expconserv2-port38
# cat file | sort -n -k 3.17,3.18
bd0hbsv1 CNAME expconserv2-port20
bd0hbsv2 CNAME expconserv2-port09
bd0hbsv3 CNAME expconserv2-port11
bd0ints2 CNAME expconserv2-port38
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2007 09:13 AM
03-29-2007 09:13 AM
Re: Sorting a list by a field
There must be a non-printable in the stream.
Or maybe a ^M stripped of in the forum paste.
Check out the file with #xd -t c file
btw... why use 'cat + pipe'?
sort is perfectly capable of reading a file directly!
If you still have trouble, be sure to attache the actual file as a .TXT to a next reply.
Regards,
Hein.
$ sort -n -k 3.17,3.18 file
01234567890123456789012345678901234567890123456789
bd0hbsv2 CNAME expconserv2-port09
bd0hbsv3 CNAME expconserv2-port11
bd0hbsv1 CNAME expconserv2-port20
bd0ints2 CNAME expconserv2-port38
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2007 09:19 AM
03-29-2007 09:19 AM
Re: Sorting a list by a field
Regarding your last question, it works for me. By the way, you don't need the extra 'cat' process! Simply:
# sort -n -k 3.17,3.18 file > file.out
Regards!
...JRF...
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2007 07:08 PM
03-29-2007 07:08 PM
Re: Sorting a list by a field
did you try to include the 'blank field skipping option' for your latest try?
sort -nb -k 3.17,3.18 file
mfG Peter
- « Previous
-
- 1
- 2
- Next »