Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

June 28 2013

Linux command – sort text file by specific column

“sort” command can specific column (“-k”) and delimiter (“-t”). Also, it can use “-n” option to specific numeric-sort.

For example:

> cat t
New,1390476,1,09:00:25,1,AAA05
New,530957,1,09:00:25,1,AAA07
New,701097,1,09:00:30,1,AAA09
New,629508,1,09:00:34,1,AAA11
New,500058,1,10:00:30,1,AAA12
New,682789,1,09:00:32,1,AAA13
New,562234,1,09:00:32,1,AAA14
New,618184,1,11:00:32,1,AAA15
New,816919,1,09:00:35,1,AAA16
New,515249,1,09:00:35,1,AAA17


> sort -k4 -t"," t
New,1390476,1,09:00:25,1,AAA05
New,530957,1,09:00:25,1,AAA07
New,701097,1,09:00:30,1,AAA09
New,682789,1,09:00:32,1,AAA13
New,562234,1,09:00:32,1,AAA14
New,629508,1,09:00:34,1,AAA11
New,816919,1,09:00:35,1,AAA16
New,515249,1,09:00:35,1,AAA17
New,500058,1,10:00:30,1,AAA12
New,618184,1,11:00:32,1,AAA15

source : http://stackoverflow.com/questions/1037365/unix-sort-with-tab-delimiter


Don't be the product, buy the product!

Schweinderl