1. 首页
  2. 宅男

Linux cut命令

Linux cut命令用于显示每行从开头算起 num1 到 num2 的文字。使用说明:cut 命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段写至标准输出。

Linux cut命令用于显示每行从开头算起 num1 到 num2 的文字。

语法

<span class="pln">cut  </span><span class="pun">[-</span><span class="pln">bn</span><span class="pun">]</span> <span class="pun">[</span><span class="pln">file</span><span class="pun">]</span><span class="pln">  cut </span><span class="pun">[-</span><span class="pln">c</span><span class="pun">]</span> <span class="pun">[</span><span class="pln">file</span><span class="pun">]</span><span class="pln">  cut </span><span class="pun">[-</span><span class="pln">df</span><span class="pun">]</span> <span class="pun">[</span><span class="pln">file</span><span class="pun">]</span>

使用说明:

cut 命令从文件的每一行剪切字节、字符和字段并将这些字节、字符和字段写至标准输出。

如果不指定 File 参数,cut 命令将读取标准输入。必须指定 -b、-c 或 -f 标志之一。

参数:

  • -b :以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
  • -c :以字符为单位进行分割。
  • -d :自定义分隔符,默认为制表符。
  • -f :与-d一起使用,指定显示哪个区域。
  • -n :取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的
    范围之内,该字符将被写出;否则,该字符将被排除

实例

当你执行who命令时,会输出类似如下的内容:

<span class="pln">$ who  rocrocket </span><span class="pun">:</span><span class="lit">0</span>           <span class="lit">2009</span><span class="pun">-</span><span class="lit">01</span><span class="pun">-</span><span class="lit">08</span> <span class="lit">11</span><span class="pun">:</span><span class="lit">07</span><span class="pln">  rocrocket pts</span><span class="pun">/</span><span class="lit">0</span>        <span class="lit">2009</span><span class="pun">-</span><span class="lit">01</span><span class="pun">-</span><span class="lit">08</span> <span class="lit">11</span><span class="pun">:</span><span class="lit">23</span> <span class="pun">(:</span><span class="lit">0.0</span><span class="pun">)</span><span class="pln">  rocrocket pts</span><span class="pun">/</span><span class="lit">1</span>        <span class="lit">2009</span><span class="pun">-</span><span class="lit">01</span><span class="pun">-</span><span class="lit">08</span> <span class="lit">14</span><span class="pun">:</span><span class="lit">15</span> <span class="pun">(:</span><span class="lit">0.0</span><span class="pun">)</span>

如果我们想提取每一行的第3个字节,就这样:

<span class="pln">$ who</span><span class="pun">|</span><span class="pln">cut </span><span class="pun">-</span><span class="pln">b </span><span class="lit">3</span><span class="pln">  c  c</span>

原创文章,作者:bfmihihc,如若转载,请注明出处:https://www.xiaomihost.com/52535.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

联系我们

400-800-8888

在线咨询:点击这里给我发消息

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息