As you can see I have 2 for loops, each outputting the contents of an array, with a little extra calculation. So, it prints in this order:
(1) Contents of the littlebin array, then
(2) Contents of the bins array
Ok, good. But, I'd like the contents of each of those arrays to be sorted numerically on the first element printed. So, I add a sort pipe:
This causes the output to be somewhat reversed, to become:
(1) Contents of the bins array, numerically sorted, then
(2) Contents of the littlebin array, numerically sorted
Why is that happening? And what is the best way of sorting as I'm attempting, on the index of each array? I've tried asorti, but it doesn't sort numerically. Thank you.
The order in which a for ( idx in array ) loop scans an array is not defined; it is generally based upon the internal implementation of arrays inside awk.
By the way you can use asort() / asorti() functions to sort array values / indices.
Post the code fragment that you used to sort numerically.
The order in which a for ( idx in array ) loop scans an array is not defined; it is generally based upon the internal implementation of arrays inside awk.
By the way you can use asort() / asorti() functions to sort array values / indices.
Post the code fragment that you used to sort numerically.
I attempted to use asorti, but I was unable to get it to sort numerically.
The code that I used is above. I simply appended " | sort -nk 1" to each "print" line. Here's the full script:
These are a couple of lines from the file it's parsing:
I attempted to use asorti, but I was unable to get it to sort numerically.
I don't see asorti function used in the code that you posted.
All you have to do is call asorti function and copy the sorted result from source array to destination array. Finally scan the destination array to print sorted result.
By the way the sort -nk 1 command usage in your code is logically wrong and is not going to help.
I don't see asorti function used in the code that you posted.
All you have to do is call asorti function and copy the sorted result from source array to destination array. Finally scan the destination array to print sorted result.
By the way the sort -nk 1 command usage in your code is logically wrong and is not going to help.
That's correct; asorti is not in my code presently. When I attempted to use it, it sorted my indices alphabetically, not numerically. It was done like this:
Hello,
I have a file with thousands of rows and I need to change sequence of lines.
Sample file:
#NAME
#SERVICE 112233
#DESCRIPTION AABBCCDD
#SERVICE 738292
#DESCRIPTION FFYYRRTT
...
...
...
Desired output:
#NAME (5 Replies)
Hi everyone,
What is the best solution to check every line in the xml file and change order of found field along with its value without touching value. Pattern will be given i.e. one line can look like this one:
<widget position="value,value" size="value,value" name="value"... (5 Replies)
hi guys
I have a service that depends on some shares (NFS shares ) that need to be mounted before before the service start so the service-app finds the NFS shares and starts correctly...
I am confused here this is what I found but I am not sure what to do in order to change it
BTW is Suse... (2 Replies)
Hi all,
Hope someone can help me out here.
I have this BASH script (see below)
My problem lies with the variable path.
The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level.
The... (6 Replies)
Good evening
I have a file as below and want to change the order, as in the second column, sed awk Pearl
Thanks
aaaaaaaaaa
bbbbbbbbb
cccccccc
aaaaaaaaaa
bbbbbbbbb
cccccccc
aaaaaaaaaa
cccccccc
bbbbbbbbb
aaaaaaaaaa
cccccccc
bbbbbbbbb (8 Replies)
Hello,
Can you tell me how can I change this format by awk
Input
0.2057422D-01
0.2463722D-01
-0.1068047D-02
Output
0.02057422
0.02463722
-0.001068047
Thanks
wan (8 Replies)
Hi everyone,
Please some help over here. (I´m using cygwing)
I have files with 40 columns and 2000 lines in average. I´m trying to change the order position as follow.
Original columns position:... (3 Replies)
I have an AIX system configured as NIS client.
I have an local user on the system called "batman" and i have a user by the same name in NIS as well.
Now when i try to login with Batman user, the local batman gets in.
How do I tell the AIX machine to authenticate Batman as NIS user?
... (2 Replies)
Hi ,
I want to change the order of a string using sed command . Is it possible ?
$echo "abc123xyz" | sed 's/\()*\) \(*\)/\2\1/'
abc123xyz
$ echo "abc123xyz" |sed 's/\()*\) \(*\) \()*\)/\2\1\3/'
abc123xyz
I want to change the string ,
abc123xyz as
xyz123abc .
Is it... (5 Replies)