格式化列表工具column和sort使用一则
来源:互联网 发布:意德法家 知乎 编辑:程序博客网 时间:2024/05/17 05:52
2012-10-20 wcdj
在对表格形式的输出数据进行处理时,column和sort工具大多可以派上用场。
看一个例子:
#/bin/sh# 2012-10-20 wcdjfile=test.txtcat << gerry_here_doc=================================usage:# m: the number of fields from onecat file | sort +(m-1) -m +(m-1) -m# useful for pretty-printing displays# -s option is specifing a set of characters to be used to delimit columns for the -t optioncat file | column -t=================================gerry_here_doctext="4 20121001-20121018 14523670 1 20121001-20121018 637368 3 20121001-20121018 308371 2 20121001-20121018 14832041 5 20121001-20121018 1.5469409E71 20121001-20121017 615608 3 20121001-20121017 305929 5 20121001-20121017 1.5271584E74 20121001-20121017 14350047 2 20121001-20121017 14655976 "echo "$text" > "$file"echo ""echo "export file named test.txt to current dir."echo "the contents of test.txt are: "cat "$file"echo "you could find that this file showing looks some confused !"echo "so, use column command to display it prettily"echo ""cat "$file" | column -techo ""echo "then, I wanna sort this file by the second field firstly and the second field next, like this: "echo ""cat "$file" | column -t | sort +1 -2 +0 -1echo ""echo "test is over"
输出内容如下:
=================================usage:# m: the number of fields from onecat file | sort +(m-1) -m +(m-1) -m# useful for pretty-printing displays# -s option is specifing a set of characters to be used to delimit columns for the -t optioncat file | column -t=================================export file named test.txt to current dir.the contents of test.txt are: 4 20121001-20121018 14523670 1 20121001-20121018 637368 3 20121001-20121018 308371 2 20121001-20121018 14832041 5 20121001-20121018 1.5469409E71 20121001-20121017 615608 3 20121001-20121017 305929 5 20121001-20121017 1.5271584E74 20121001-20121017 14350047 2 20121001-20121017 14655976 you could find that this file showing looks some confused !so, use column command to display it prettily4 20121001-20121018 145236701 20121001-20121018 6373683 20121001-20121018 3083712 20121001-20121018 148320415 20121001-20121018 1.5469409E71 20121001-20121017 6156083 20121001-20121017 3059295 20121001-20121017 1.5271584E74 20121001-20121017 143500472 20121001-20121017 14655976then, I wanna sort this file by the second field firstly and the second field next, like this: 1 20121001-20121017 6156082 20121001-20121017 146559763 20121001-20121017 3059294 20121001-20121017 143500475 20121001-20121017 1.5271584E71 20121001-20121018 6373682 20121001-20121018 148320413 20121001-20121018 3083714 20121001-20121018 145236705 20121001-20121018 1.5469409E7test is over
参考:
[1] column http://linux.about.com/library/cmd/blcmdl1_column.htm
[2] sort http://linux.about.com/library/cmd/blcmdl1_sort.htm
- 格式化列表工具column和sort使用一则
- [小工具] Linux下列格式化工具 - column
- column sort
- Oracle格式化输出列COLUMN的使用
- sort工具的使用
- sort工具的使用
- oracle命令的使用:使用column格式化显示列命令
- Insert sort样例一则
- salesforce table column sort
- IAR 工具使用AStyle工具格式化代码
- JSON格式化工具和beyondcompare对比工具
- 列表边框column-rule
- extjs override grid column sort
- CSS代码格式化和JS代码格式化工具
- sscanf 使用一则
- 使用Hibernate注意事项一则
- service使用范例一则
- repo使用问题一则
- 童话 谢幕了。梦也该醒了:伤感日志
- Ruby on Rails,使用find方法加载持久化对象
- VS2010 无边框窗口拉伸无法获取WM_NCLBUTTONUP消息
- 关于圆锥的计算
- C语言的基本数据类型及数据类型转换
- 格式化列表工具column和sort使用一则
- Servlet中request.sendRedirect()不起作用
- 用递归实现查找字符串中相同字符连续出现次数的最大值
- 掏心的爱给了没肺的你。
- 字符串操作
- 按某几列删除表中重复数据
- 短信拦截,如何抢先于QQ通讯录,360
- 小幸福的伤感空间日志分享:爱的,我们不适合拥抱,只适合依靠
- 《programming in lua》(1)