How do I sort data in column properly?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How do I sort data in column properly?
# 1  
Old 05-16-2018
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 youSmilie

Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 05-16-2018 at 05:10 AM.. Reason: Added CODE tags.
# 2  
Old 05-16-2018
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; 05-16-2018 at 06:35 AM..
This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-16-2018
Thank you very much RudiCSmilie. Now, how do i output it into the new file?
# 4  
Old 05-17-2018
Quote:
Originally Posted by nurul_nadzirah
Thank you very much RudiCSmilie. 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.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with sort only column 2 data separately

Input File Contig_1_294435nt 242231 242751 Contig_1_294435nt 242390 242782 Contig_1_294435nt 242390 242782 Contig_1_294435nt 291578 291668 Contig_2_242278nt 75910 76271 Contig_2_242278nt 76036 76316 Contig_2_242278nt 76036 76316... (2 Replies)
Discussion started by: perl_beginner
2 Replies

2. Shell Programming and Scripting

Sort data by date and then search by column

Hi, I have a file where data is pipe separated.First i want to sort the file content by date . Then i want to pick up the records based on the first column which should be unique and not have duplicates. NYSE|yyyrrrddd|toronto|isin|ticker|2013-05-15... (2 Replies)
Discussion started by: samrat dutta
2 Replies

3. Shell Programming and Scripting

Why is sort not working properly here ?

Platform: RHEL 5.4 In the below text file I have strings like following. $ cat /tmp/mytextfile.txt DISK1 DISK10 DISK101 DISK102 DISK103 DISK104 DISK105 DISK106 DISK107 DISK108 DISK109 DISK110 DISK111 DISK112 DISK113 DISK114 (8 Replies)
Discussion started by: kraljic
8 Replies

4. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

5. Shell Programming and Scripting

Advanced: Sort, count data in column, append file name

Hi. I am not sure the title gives an optimal description of what I want to do. Also, I tried to post this in the "UNIX for Dummies Questions & Answers", but it seems no-one was able to help out. I have several text files that contain data in many columns. All the files are organized the same... (14 Replies)
Discussion started by: JamesT
14 Replies

6. Shell Programming and Scripting

Sort data As per first Column

hI I have file A NSU30504 5 6 G 6 NSU3050B T 7 9 J NSU30506 T I 8 9 NSU3050C H J K L Output: NSU3050B T 7 9 J NSU3050C H J K L NSU30504 5 6 G 6 NSU30506 T I 8 9Video tutorial on how to use code tags in The UNIX and Linux Forums. (13 Replies)
Discussion started by: pareshkp
13 Replies

7. Shell Programming and Scripting

Sort data from column to row

Hi, I need somebody's help with sorting data with awk. I've got a file: 10 aaa 4584 12 bbb 6138 20 ccc 4417 21 ddd 7796 10 eee 7484 12 fff ... (5 Replies)
Discussion started by: killerbee
5 Replies

8. Shell Programming and Scripting

Align the values in column properly

This is my input,is it possible to do a bit of scripting on this to produce a properly alligned output. I/P -0.015 0.021 0.056 0.073 0.061 0.020 -0.038 -0.090 -0.113 -0.091 -0.025 0.064 0.141 0.170 0.130 0.027 -0.106 -0.215 -0.249 -0.181 -0.024 0.169 0.319 0.356 0.245 0.011 -0.262 -0.465... (6 Replies)
Discussion started by: Indra2011
6 Replies

9. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

10. Shell Programming and Scripting

Korn: How to zero fill df output so it will sort properly

I'm looking for a way in Korn shell to zero fill (or space fill) the output from df so that it will sort properly. "Raw" output from df -k: df -k Filesystem kbytes used avail capacity Mounted on /dev/vx/dsk/rootvol 4131866 3593302 497246 88% / /proc ... (9 Replies)
Discussion started by: shew01
9 Replies
Login or Register to Ask a Question