文本处理按列排序

作者: LiHui 分类: Shell 发布时间: 2016-05-29 22:18

除了写个脚本,直接通过sort命令也挺快

lihui@MacBook  ~  cat lihui.txt
one     1
ten     10
five    5
four    4
six     6
nine    9
three   3
serven  7
two     2
eight   8

 

按第二列顺序

lihui@MacBook  ~  cat lihui.txt | sort -k2n
one     1
two     2
three   3
four    4
five    5
six     6
serven  7
eight   8
nine    9
ten     10

 

按第二列逆序

lihui@MacBook  ~  cat lihui.txt | sort -k2nr
ten     10
nine    9
eight   8
serven  7
six     6
five    5
four    4
three   3
two     2
one     1

 

按第一列逆序

lihui@MacBook  ~  cat lihui.txt | sort -k1nr
eight   8
five    5
four    4
nine    9
one     1
serven  7
six     6
ten     10
three   3
two     2

 

OVER

纯属恶搞

浙ICP备16024533号

浙公网安备 33010802007459号