按列长排序

堆栈堆栈和堆栈

需要帮助使用 Unix 命令按第 4 列的长度排序。

示例数据(所有数据都是组成的,而不是实际的)。

5032:Stack:[email protected]:123:JamesPeterson
3200:Admin:[email protected]:12ej3dij23i2j32:AdminAdmin
1024:GregoryJames:[email protected]:12329232:GregJames

首选格式(因为第 4 列的长度最长)。

3200:Admin:[email protected]:12ej3dij23i2j32:AdminAdmin
1024:GregoryJames:[email protected]:12329232:GregJames
5032:Stack:[email protected]:123:JamesPeterson
巴马

使用awk添加包含列的长度的列,排序的是,然后将其删除。

awk -F: '{printf("%d %s\n", length($4), $0)}' input.txt | sort -nr | cut -d' ' -f2- > output.txt

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章