LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-26-2014, 12:22 PM   #16
a_bahreini
LQ Newbie
 
Registered: Mar 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled

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
 
Old 03-26-2014, 12:38 PM   #17
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
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
 
Old 03-26-2014, 12:45 PM   #18
a_bahreini
LQ Newbie
 
Registered: Mar 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
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.
 
Old 03-26-2014, 09:05 PM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,244

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash suggestions to convert horizontal columns to vertical columns Guyverix Programming 14 01-24-2013 12:03 PM
[SOLVED] sorting alphanumeric columns captainentropy Programming 5 09-14-2011 02:14 PM
sorting text file on different columns in different orders arshadul Linux - Newbie 1 10-19-2009 03:15 PM
Bash script sorting multple columns together KBriggs Linux - Newbie 2 08-13-2009 01:59 PM
sorting columns in bash twistadias Linux - Newbie 8 08-25-2008 01:22 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration