sorting

How can I remove selected lines with an awk script?

I'm piping a program's output through some awk commands, and I'm almost where I need to be. The command thus far is: myprogram | awk '/chk/ { if ( $12 > $13) printf("%s %d\n", $1, $12 - $13); else printf("%s %d\n", $1, $13 - $12) } ' | awk '!x[$0]++' The last bit is a poor man's uniq, which isn't available on my target. Given the...

Sorting by Price with SQL data type VARCHAR

I´m sorting by Price, look: SELECT Price FROM re2_listings ORDER BY Price asc Result: 1.200.000,00 1.500.000,00 200,00 3.000,00 ...but the correct way is: 200,00 3.000,00 1.200.000,00 1.500.000,00 Understand? How to do this? ...

How can I maintain display order in UITableView using Core Data?

Hi All, I'm having some trouble getting my Core Data entities to play nice and order when using an UITableView. I've been through a number of tutorials and other questions here on StackOverflow, but there doesn't seem to be a clear or elegant way to do this - I'm really hoping I'm missing something. I have a single Core Data entity tha...

Sorting blocks of L elements

I have an array of N * L integers int array[N * L]; I want to divide the array in N blocks of L elements and sort the blocks according to the classic list comparison (compare first element, than second, etc). In C I can do: qsort(array, N, sizeof(int) * L, comp); How can I achieve the same result using C++ std::sort(...) which is,...

How to sort DataTable by 2 columns, with NULLs, maybe using LINQ?

I have an ADO.Net datatable that I need to sort by first by column1 then by column2, either of which may have nulls. Once sorted I need to read some values out of the rows and add to a listview. I have written code to do this DataTable.DefaultView.Sort (run twice). But wondering if there might be a better way. I was thinking maybe ...

How to fix this bubble sort program?

package arraySort; import java.io.IOException; import java.io.File; import java.util.*; public class openFile { int x; static int i; static int[] myList = {100}; public static void main(String[] args){ try{ File myFile = new File("arraySort.txt"); Scanner scan = new Scanner(myFile); ...

Between code (C#, Java) and database (SQL) where should we sort or filter?

Between code (C#, Java) and database (SQL) where should we sort or filter? In code it means having a single stored procedure to retrieve all data from the database and then filter my data (in the business or data layer). In database it means having a stored procedure. In this case the code (data layer) send my filter settings to stored...

Sorting an array / a variable by first letter in PHP

How can you sort the following word by the given rule? Example data is saapas which I want to be either aaapss or in the array s a a p a s and then somehow a a a p s s The function arsort with sort_flags SORT_REQULAR and SORT_STRING did not work for me. ...

Passing an array of arbitrary struct pointers to a C function?

I want to pass an array of arbitrary struct pointers and a comparison function to a generic sorting algorithm. Is this possible in C? The goooeys of the structs would only be accessed within the comparison function, the sorting function would only need to call the comparison function and swap pointers, but I can't figure out how to decl...

Help sorting: first by this, and then by that ...

I have a list of tuples I am trying to sort and could use some help. The field I want to sort by in the tuples looks like "XXX_YYY". First, I want to group the XXX values in reverse order, and then, within those groups, I want to place the YYY values in normal sort order. (NOTE: I am just as happy, actually, sorting the second item ...

Failed to compare two elements in the array

I have a List where T is a class that exposes a "Username" property. Username is of a custom type that encapsulates a string. I implemented the IComparable<T> interface on this custom type that simply returns this.encapsulatedString.CompareTo(other.encapsulatedString) I defined an ICollectionView of the List thus: AllUsers=Collection...

How to group columns by sum in R

Let's say I have two columns of data. The first contains categories such as "First", "Second", "Third", etc. The second has numbers which represent the number of times I saw "First". For example: Category Frequency First 10 First 15 First 5 Second 2 Third 14 Third 20 Second 3 I want ...

Shell script sort list

I have a list with the following content: VIP NAME DATE ARRIVE_TIME FLIGHT_TIME 1 USER1 11-02 20.00 21.00 3 USER2 11-02 20.45 21.45 4 USER2 11-03 20.00 21.30 2 USER1 11-04 17.20 19.10 I want to sort this and similar lists with a shell script. The result should be a new list with lines that do not collide....

Ordering elements by number in JQuery

Hi, how could I arrange the following div's by the value in the attribute amount with jquery? Thanks. <a href="#" id="id1" class="lTest" amount="12"> <div>abcd1</div> <a/> <a href="#" id="id2" class="lTest" amount="64"> <div>abcd2</div> <a/> <a href="#" id="id3" class="lTest" amount="32"> <div>abcd3</div> <a/> <a href="#"...

Why is my merge sort not working?

It compiles fine, but when it runs, it adds random high numbers to the list, as well as duplicates of existing numbers. I've had a couple of people look over this, and none of them can figure it out. void mergeSort(int list[], int length) { recMergeSort(list, 0, length - 1); } void recMergeSort(int list[], int first, int last) { ...

Speed of Javascript array sort dependent on object size?

Hey out there in Stackland. I'm making a very javascript-heavy site, and at a certain point I have to take a whole bunch of objects in an array and then sort them by their distance from a certain point. I don't know the nature of objects in JS, and was wondering if this array sort would take longer with larger objects, or if it is the ...

Velocity sort XML file with dynamic-elements

Let's say I have a XML file wich looks like this: <root> <dynamic-element name='name' type='text' repeatable='true'> <dynamic-element name='prename' type='text' repeatable='false'> </dynamic element> </dynamic-element> </root> In Liferay the XML file will be filled with input. At the and I will have multiple $name-elements. T...

MySQL Rating/Voting system (accurratly ordering by best rated taking into account number of votes)

Let's say I have a MySQL table that is something like this: software table: id int name text votes int rating int Where votes would be the number of times someone has voted for that item and rating would be the average of those votes. Example data: id: 0 name: FooBar! votes: 5 rating: 3 Now another user comes along and rates this...

How to sort by line length, then reverse alphabetically

I have a large (600 odd) set of search and replace terms that I need to run as a sed script over some files. The problem is that the search terms are NOT orthogonal... but I think I can get away with it by sorting by line length (i.e. pull out the longest matches first, and then alphabetically within each length. So given an unsort set o...

Inserting items in a list that is frequently insertion sorted

I have a list that is frequently insertion sorted. Is there a good position (other than the end) for adding to this list to minimize the work that the insertion sort has to do? ...