I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this:
abc ||| 5e-05 ||| bla
abc ||| 3 ||| ble
def ||| 1 ||| abc
def ||| 0.2 ||| def
As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Hi,
This is my input file:
ali 5 usa abc
abu 4 uk bca
alan 6 brazil bac
pinky 10 utah sdc
My desired output:
pinky 10 utah sdc
alan 6 brazil bac
ali 5 usa abc
abu 4 uk bca
Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers.
like:
19383882872201110929282821818182827349190102837364718191001932873711
Now, each number is part of a numerical value of... (4 Replies)
Hello all -
I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
I have a column of numbers in the following format:
1.722e-05
2.018e-05
2.548e-05
2.747e-05
7.897e-05
4.016e-05
4.613e-05
4.613e-05
5.151e-05
5.151e-05
5.151e-05
6.1e-05
6.254e-05
7.04e-05
7.12e-05
7.12e-05 (6 Replies)
Input file:
100%ABC2 3.44E-12 USA
A2M%H02579 0E0 UK
100%ABC2 5.34E-8 UK
100%ABC2 3.25E-12 USA
A2M%H02579 5E-45 UK
Output file:
100%ABC2 3.44E-12 USA
100%ABC2 3.25E-12 USA
100%ABC2 5.34E-8 UK
A2M%H02579 0E0 UK
A2M%H02579 5E-45 UK
Code try:
sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Hi Experts,
I have a filelist collected from another server , now want to sort the output using date/time stamp filed.
- Filed 6, 7,8 are showing the date/time/stamp.
Here is the input:
#----------------------------------------------------------------------
-rw------- 1 root ... (3 Replies)
Hi,
PROCINFO seems to be a great function but I don't manage to make it works.
input:
B,A,C
B
B,B
As an example, just want to count the occurence of each letter across the input and sort them by decreased order.
Wanted output:
B 4
A 1
C 1
When I use this command, the PROCINFO... (4 Replies)
Discussion started by: beca123456
4 Replies
LEARN ABOUT PHP
sort
SORT(3) 1 SORT(3)sort - Sort an arraySYNOPSIS
bool sort (array &$array, [int $sort_flags = SORT_REGULAR])
DESCRIPTION
This function sorts an array. Elements will be arranged from lowest to highest when this function has completed.
PARAMETERS
o $array
- The input array.
o $sort_flags
- The optional second parameter $sort_flags may be used to modify the sorting behavior using these values: Sorting type flags:
o SORT_REGULAR - compare items normally (don't change types)
o SORT_NUMERIC - compare items numerically
o SORT_STRING - compare items as strings
o SORT_LOCALE_STRING - compare items as strings, based on the current locale. It uses the locale, which can be changed using
setlocale(3)
o SORT_NATURAL - compare items as strings using "natural ordering" like natsort(3)
o SORT_FLAG_CASE - can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
RETURN VALUES
Returns TRUE on success or FALSE on failure.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.4.0 | |
| | |
| | Added support for SORT_NATURAL and |
| | SORT_FLAG_CASE as $sort_flags |
| | |
| 5.0.2 | |
| | |
| | Added SORT_LOCALE_STRING |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
sort(3) example
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "
";
}
?>
The above example will output:
fruits[0] = apple
fruits[1] = banana
fruits[2] = lemon
fruits[3] = orange
The fruits have been sorted in alphabetical order.
Example #2
sort(3) example using case-insensitive natural ordering
<?php
$fruits = array(
"Orange1", "orange2", "Orange3", "orange20"
);
sort($fruits, SORT_NATURAL | SORT_FLAG_CASE);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "
";
}
?>
The above example will output:
fruits[0] = Orange1
fruits[1] = orange2
fruits[2] = Orange3
fruits[3] = orange20
The fruits have been sorted like natcasesort(3).
NOTES
Note
This function assigns new keys to the elements in $array. It will remove any existing keys that may have been assigned, rather than
just reordering the keys.
Note
Like most PHP sorting functions, sort(3) uses an implementation of Quicksort. The pivot is chosen in the middle of the partition
resulting in an optimal time for already sorted arrays. This is however an implementation detail you shouldn't rely on.
Warning
Be careful when sorting arrays with mixed types values because sort(3) can produce unpredictable results.
SEE ALSO asort(3), The comparison of array sorting functions.
PHP Documentation Group SORT(3)