03-07-2019
Did you set the IFS variable as indicated?
Try the sort keys given with netzabudka's proposal as well.
This User Gave Thanks to RudiC For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
i'm trying to open a file with three or more columns and an undetermined, but finite number of rows. I want to define an array for each row with each element of the row as a sub array. The columns are separated by tabs or spaces.
Here's the file:
12x3.12z34b.342sd3.sds 454.23.23.232 ... (9 Replies)
Discussion started by: prkfriryce
9 Replies
2. Shell Programming and Scripting
Hello Experts,,
Can anybody give me a brief idea what is following bold letter statement is for!!
what is the term called so that I can google for it..
It seems to be an array inside another array..
awk'
/TXADDR/ { txaddr=$NF } ##understood
/TXDATA/ { txdata]=$NF... (1 Reply)
Discussion started by: user_prady
1 Replies
3. Shell Programming and Scripting
In a single dim. awk array, we can use :
<index> in <array name>
to determine whether a particualar index exists in the array or not.
Is there a way to achieve this in a awk multi dim. array ? (4 Replies)
Discussion started by: sinpeak
4 Replies
4. Programming
Hi! I need to make dynamic multidimensional arrays using the vector class. I found in this page How to dynamically create a two dimensional array? - Microsoft: Visual C++ FAQ - Tek-Tips the way to do it in 2D, and now i'm trying to expand it to 3D but i don't understand how is the operator working,... (0 Replies)
Discussion started by: carl.alv
0 Replies
5. Shell Programming and Scripting
Hi,
I was trying to process a file with the help of awk. I want to first display all the rows that contains 01 and at the end of processing I have to print some portion of all the lines. like below.
Output expected: (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies
6. Programming
I've been struggling with this for quite some time. I decided I should get some help with this. Nothing is working. I'm getting a segmentation fault or out of bounds error when I try to load the entries in the for loop.I'm really frustrated. :mad: Compiling isn't the problem. It's crapping out on... (5 Replies)
Discussion started by: sepoto
5 Replies
7. Programming
My language is C++. I have a multidimensional vector that I would like to sort by a specific "cell" or "field" within the main vector. Does anyone have any information on how to do this? I have searched all over the internet and every reference manual I can find. So far I have found very little to... (2 Replies)
Discussion started by: sepoto
2 Replies
8. Shell Programming and Scripting
I have an awk script that I am writing and I needed to make use of a multidimensional array to hold some data... Which is all fine but I need to loop through that array now and I have no idea how to do that.
for a regular array, the following works:
ARRAY
for(var in ARRAY) {
...
}
... (5 Replies)
Discussion started by: trey85stang
5 Replies
9. Shell Programming and Scripting
Hi all!
I would like to know how to print $0 when using multidimensional array like below
time being I am using for loop to print columns like this
awk 'FNR==1{i++}
{for(k=1;k<=NF;k++)A=$k}
END{for(j=1;j<=25;j++)
print A,A,A,A,A,A,A,A,A,A,A,A,A,A}' file1 file2 so here my problem is I... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies
10. Shell Programming and Scripting
I am learning about bash system variables, such as $ , @ and #.
I have this piece of script implementing an array and it is doing its job just fine.
This is not the only array I will be using.
Just for ease of maintenance and more coding I would like to have the arrays in two dimensional... (4 Replies)
Discussion started by: annacreek
4 Replies
NATSORT(3) 1 NATSORT(3)
natsort - Sort an array using a "natural order" algorithm
SYNOPSIS
bool natsort (array &$array)
DESCRIPTION
This function implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value
associations. This is described as a "natural ordering". An example of the difference between this algorithm and the regular computer
string sorting algorithms (used in sort(3)) can be seen in the example below.
PARAMETERS
o $array
- The input array.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
|5.2.10 | |
| | |
| | Zero padded numeric strings (e.g., '00005') now |
| | essentially ignore the 0 padding. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
natsort(3) examples demonstrating basic usage
<?php
$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png");
asort($array1);
echo "Standard sorting
";
print_r($array1);
natsort($array2);
echo "
Natural order sorting
";
print_r($array2);
?>
The above example will output:
Standard sorting
Array
(
[3] => img1.png
[1] => img10.png
[0] => img12.png
[2] => img2.png
)
Natural order sorting
Array
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
For more information see: Martin Pool's Natural Order String Comparison page.
Example #2
natsort(3) examples demonstrating potential gotchas
<?php
echo "Negative numbers
";
$negative = array('-5','3','-2','0','-1000','9','1');
print_r($negative);
natsort($negative);
print_r($negative);
echo "Zero padding
";
$zeros = array('09', '8', '10', '009', '011', '0');
print_r($zeros);
natsort($zeros);
print_r($zeros);
?>
The above example will output:
Negative numbers
Array
(
[0] => -5
[1] => 3
[2] => -2
[3] => 0
[4] => -1000
[5] => 9
[6] => 1
)
Array
(
[2] => -2
[0] => -5
[4] => -1000
[3] => 0
[6] => 1
[1] => 3
[5] => 9
)
Zero padding
Array
(
[0] => 09
[1] => 8
[2] => 10
[3] => 009
[4] => 011
[5] => 0
)
Array
(
[5] => 0
[1] => 8
[3] => 009
[0] => 09
[2] => 10
[4] => 011
)
SEE ALSO
natcasesort(3), The comparison of array sorting functions, strnatcmp(3), strnatcasecmp(3).
PHP Documentation Group NATSORT(3)