Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

How do I sort data in column properly?

UNIX for Beginners Questions & Answers


Tags
column, justify, standard

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nurul_nadzirah
nurul_nadzirah's Unix or Linux Image
nurul_nadzirah nurul_nadzirah is offline
Registered User
 
Join Date: May 2018
Last Activity: 17 May 2018, 8:37 PM EDT
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
How do I sort data in column properly?

Can i use 'column' command to get the required 3rd column output?

Input example:



Code:
1 2 345678 90
2 2 356       42
3 3 8265     55

Output required:



Code:
1 2 345678 90
2 2      356  42
3 3    8265  55

Basically i want the 3rd column to be justified to the right, instead of left. '>>column -t' command somehow makes it skewed to the left.

Thank youLinux

Moderator's Comments:
How do I sort data in column properly? Please use CODE tags as required by forum rules!

Last edited by RudiC; 1 Week Ago at 04:10 AM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nurul_nadzirah
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 28 May 2018, 3:43 AM EDT
Location: Aachen, Germany
Posts: 12,756
Thanks: 417
Thanked 3,923 Times in 3,607 Posts
Welcome to the forum.

How about


Code:
rev file | column -t | rev
1  2  345678  90
2  2     356  42
3  3    8265  55

Be aware that this will right justify every column.

Last edited by RudiC; 1 Week Ago at 05:35 AM..
The Following User Says Thank You to RudiC For This Useful Post:
nurul_nadzirah (1 Week Ago)
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nurul_nadzirah
nurul_nadzirah's Unix or Linux Image
nurul_nadzirah nurul_nadzirah is offline
Registered User
 
Join Date: May 2018
Last Activity: 17 May 2018, 8:37 PM EDT
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you very much RudiCLinux. Now, how do i output it into the new file?
    #4  
Old Unix and Linux 1 Week Ago   -   Original Discussion by nurul_nadzirah
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 28 May 2018, 3:27 AM EDT
Location: San Jose, CA, USA
Posts: 11,313
Thanks: 639
Thanked 3,938 Times in 3,368 Posts
Quote:
Originally Posted by nurul_nadzirah View Post
Thank you very much RudiCLinux. Now, how do i output it into the new file?
What new file? There is no mention of a new file in post #1 in this thread?

What shell are you using?

What operating system are you using?

For many shells on many operating systems, the command:


Code:
rev oldfile | column -t | rev > newfile

would reformat the contents of a file named oldfile into a new file named newfile.
The Following User Says Thank You to Don Cragun For This Useful Post:
nurul_nadzirah (1 Week Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with sort only column 2 data separately perl_beginner Shell Programming and Scripting 2 02-18-2016 04:05 AM
Sort data by date and then search by column samrat dutta Shell Programming and Scripting 2 05-17-2013 10:23 AM
Advanced: Sort, count data in column, append file name JamesT Shell Programming and Scripting 14 08-14-2012 07:36 AM
Sort data As per first Column pareshkp Shell Programming and Scripting 13 02-26-2012 01:16 PM
Sort data from column to row killerbee Shell Programming and Scripting 5 02-10-2012 04:50 PM



All times are GMT -4. The time now is 04:08 AM.