基于在一个文件中的第二列的值排序数据 [英] Sorting data based on the value in second column of a file

查看:147
本文介绍了基于在一个文件中的第二列的值排序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列的文件和 N 的行数。

I have a file of two columns and n number of rows.

1列包含名称和列2 年龄

我要根据此文件的升序排列的内容进行分类年龄(在第二列)。

I want to sort the content of this file in ascending order based on the age (in second column).

结果应该显示名称名称沿着最年轻的人,然后第二个最年轻的人等...

The result should display the name of the youngest person along with name and then second youngest person and so on...

对于单行shell或bash脚本的任何建议。

Any suggestions for a one liner shell or bash script.

推荐答案

您可以使用排序命令:

sort -k2 -n yourfile

例如:

$ cat ages.txt 
Bob 12
Jane 48
Mark 3
Tashi 54
$ sort -k2 -n ages.txt 
Mark 3
Bob 12
Jane 48
Tashi 54

这篇关于基于在一个文件中的第二列的值排序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆