LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 11:22 AM   #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, 11:38 AM   #17
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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, 11:45 AM   #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, 08:05 PM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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



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 11:03 AM
[SOLVED] sorting alphanumeric columns captainentropy Programming 5 09-14-2011 01:14 PM
sorting text file on different columns in different orders arshadul Linux - Newbie 1 10-19-2009 02:15 PM
Bash script sorting multple columns together KBriggs Linux - Newbie 2 08-13-2009 12:59 PM
sorting columns in bash twistadias Linux - Newbie 8 08-25-2008 12:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:05 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
Open Source Consulting | Domain Registration