GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- gawk asort function
Operating System - HP-UX
1847902
Members
3242
Online
104021
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-28-2008 06:39 PM
08-28-2008 06:39 PM
gawk asort function
Hi, I google a bit but couldn't find what I need. Hope some expert can help me.
I have an array stored with numeric data, however when I call the asort(array) function, The sorted array is based on string comparision (1, 10, 11, 2, 20, 3, 4,5 ..). How do I sort in numeric order (1,2,3,4,...), I need to do this in gawk.
thanks,
I have an array stored with numeric data, however when I call the asort(array) function, The sorted array is based on string comparision (1, 10, 11, 2, 20, 3, 4,5 ..). How do I sort in numeric order (1,2,3,4,...), I need to do this in gawk.
thanks,
- Tags:
- gawk
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2008 07:35 PM
08-28-2008 07:35 PM
Re: gawk asort function
I have no problems with gawk 3.1.4 and numeric values with asort. Provided the values weren't in quotes to start:
gawk '
BEGIN {
s[10] = 2
s[11] = 1
s[12] = 3
s[13] = 10
asort(s)
print s[1]
print s[2]
print s[3]
print s[4]
for (i in s)
print i, s[i]
exit
}' /dev/null
gawk '
BEGIN {
s[10] = 2
s[11] = 1
s[12] = 3
s[13] = 10
asort(s)
print s[1]
print s[2]
print s[3]
print s[4]
for (i in s)
print i, s[i]
exit
}' /dev/null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2008 05:15 AM
08-29-2008 05:15 AM
Re: gawk asort function
Hi:
Perl offers the ability to sort in numeric versus alphabetic order merely by switching to the "spaceship" operator from the 'cmp' operator. Consider:
# perl -le '@n=qw(2 1 3 10);print for sort {$a <=> $b} @n'
1
2
3
10
...instead of:
# perl -le '@n=qw(2 1 3 10);print for sort {$a cmp $b} @n'
1
10
2
3
...As you see, Perl would have solved a problem that forced you to move from 'awk' to 'gawk' anyway :-}}
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1262693
Regards!
...JRF...
Perl offers the ability to sort in numeric versus alphabetic order merely by switching to the "spaceship" operator from the 'cmp' operator. Consider:
# perl -le '@n=qw(2 1 3 10);print for sort {$a <=> $b} @n'
1
2
3
10
...instead of:
# perl -le '@n=qw(2 1 3 10);print for sort {$a cmp $b} @n'
1
10
2
3
...As you see, Perl would have solved a problem that forced you to move from 'awk' to 'gawk' anyway :-}}
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1262693
Regards!
...JRF...
- Tags:
- Perl
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2026 Hewlett Packard Enterprise Development LP