LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sorting columns individually (https://www.linuxquestions.org/questions/linux-newbie-8/sorting-columns-individually-4175499479/)

a_bahreini 03-26-2014 11:22 AM

Ok this is what I have done based on what schneidz said. Here I've cut all the columns:
Code:

cut -f 0- myfile
I just don't know how to paste columns into different files so I can sort with this:
Code:

sort -f '|' -k3

schneidz 03-26-2014 11:38 AM

here is what i get when i run you cut command:
Code:

[schneidz@hyper ~]$ cat bahreini.txt
2|3|40|50        21|32|60|70
12|40|30|60        34|21|50|80
43|33|20|21        54|23|70|56
[schneidz@hyper ~]$ cut -f 0- bahreini.txt



[schneidz@hyper ~]$

personally, i would run the cut command like this:
Code:

[schneidz@hyper ~]$ cut -f 1 bahreini.txt | tee bahreini.1
2|3|40|50
12|40|30|60
43|33|20|21
[schneidz@hyper ~]$ cut -f 2 bahreini.txt | tee bahreini.2
21|32|60|70
34|21|50|80
54|23|70|56


a_bahreini 03-26-2014 11:45 AM

Thanks schneidz but I can do this with awk too. Do you expect me to do that for 41 fields individually?!! I was looking for a simpler solution.

grail 03-26-2014 08:05 PM

Did you try my suggestion? Assuming latest version of awk (4+) you could easily do multi-dimensional arrays on the fly and process everything in the END section.


All times are GMT -5. The time now is 01:37 PM.