linux命令学习之cut

本文发布时间: 2019-Mar-22
cut命令也是linux下最常用的命令之一。正如其名,cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的。cut是以每一行为一个处理对象的,这种机制和sed是一样的。cut命令的剪切度量有三种:按字节剪切:-b(byte)按字符剪切:-c(character)按域剪切 :-f(field) 按域剪切时需要指定分割符,默认分割符是制表符( ).此外,cut命令还支持数字表示的范围,N N'th byte, character or field, counted from 1N- from N'th byte, character or field, to end of lineN-M from N'th to M'th (included) byte, character or field-M from first to M'th (included) byte, character or field举例子来说明一下:按照字节剪切date | cut -b 1-52014date | cut -b 1-62014date | cut -b 1-72014年从上面的例子可以看出汉字“年”占了3个字节按照字符剪切date2014年 10月 10日 星期五 14:48:16 CSTdate | cut -c 1,3,4214多个定位之间用逗号隔开按照域剪切date2014年 10月 10日 星期五 14:46:09 CSTdate | cut -d" " -f 4,5星期五 14:46:12-d指示分割符 并且分割符必须是单字符。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表