cut用法

cut命令用来剪下文本文件里的数据,文本文件可以是字段类型或是字符类型。

cut - remove sections from each line of files

语法

cut  OPTION...  [FILE]...

选项

-b --bytes=list        #select only these bytes  

-c --characters=list    #select only these characters   #以字符为主,执行剪下的操作。list为字符编号或一段范围的列表(以逗号分割),如1,3,5-12,42。

-d --delimiter=DELIM   #use DELIM instead of TAB for filed delimiter

-f --fields=list    #select only these fields; also print any line that contains no delimiter character, unless the -s option is specified. #以字段为主操作。list为字段编号或一段范围的列表(以逗号分割)。

-s --only-delimited   #do not print lines not containing delimiters.

行为模式

剪下输入字符中指定的字段或指定的范围。若处理的是字段,则定界符隔开的即为各字段,而输出时字段也以给定的定界符隔开。

举例

cut -d : -f 1,5 /etc/passwd     #取出字段

cut -d : -f 1,6 /etc/passwd    #取出根目录

注:POSIX系统下,cut识别多字节字符。因此,“字符character”与“字节byte”意义不同。

有些系统对输入行的大小有限制,尤其是含有多字节字符时。

原文地址:https://www.cnblogs.com/embedded-linux/p/6240159.html