sorting columns individually
Hi,
I have a file full of this fields and rows (this is showing two rows and two columns but my file has more rows and columns): Code:
0.269330|0.035118|0.526763|0.792274 0.33555|19.471911|51.844968|1631 ... Thanks |
You may need to explain a little further as it does not appear clear what you require (at least to me).
If you have 2 rows by 2 columns, what do the '...' represent? If you are using a single field as the reference, you then say you want to sort each column based on this. If there is only one reference point, won't all the columns end up in the same position after sorting? |
Sorry for the confusion. "..." means just that I have more of those fields and rows, please ignore those. My file has 41 fields and 60 rows. I have only inputed two rows and two columns in my last post. I don't want to sort based on a particular field but I'd like to sort each column by itself based on the number after third vertical bar on that column. I just wanted 41 sorted columns in my output. Hope this helped
|
In the field after the 3rd '|' you have a field that has "number< some spaces >anothernumber"
That looks really odd.... How about posting some real data eg 5 cols, 5 rows and use CODE tags https://www.linuxquestions.org/quest...do=bbcode#code and possibly re-phrase the qn. Thx. |
Hi Chrism01,
That's not "some space" but a "tab". The file is tab delimited. Each field has a bunch of numbers separated by "|". |
ok ... using your current example (although I think chrism01 might be right that a couple more lines may help)
please show what the output would look like after the sort has been completed? |
for small things like this using a spread sheet is likely the best tool
excel or the Openoffice Equiv. " Calc" is very good at things like this |
This
[quote] sort each column by itself [/code] makes sense. This Code:
based on the number after third vertical bar on that column Do you mean 'on that row' ? Also, which number, if each field has multiple numbers; 1st, 2nd, 3rd ...? As per grail, we need example o/p after sorting. |
Ok, let's make this simple. Here is two columns of my file:
Code:
2|3|40|50 21|32|60|70 Code:
43|33|20|21 34|21|50|80 Thanks in advance |
what have you tried and where are you stuck ?
i would cut each grouping into its own file then sort by the 3rd key delimited by '|' then paste the result back to 1 file separated by tab. |
Thanks schneidz for the solution but can I do this in a single command line? How can I "cut" all the columns into the individual fields?
|
man cut
|
You can make use of multiple delimiters in awk. something like this...
Code:
$ cat file |
Based on post #3, I would use your favourite tool (awk, perl, ruby, ...) and create 41 arrays / hashes with 60 elements using the third pipe separated number as the index.
Then either sort or regurgitate the numbers in the order required. This would require that none of the pipe separated third fields are repeated ... can you guarantee this? If you cannot, how is the sort supposed to know where to look after this field? |
Quote:
|
All times are GMT -5. The time now is 04:13 PM. |