• 要找福利?记不住网址?搜不到?如何与我们保持联系?试试 CTRL+D 把零点博客添加进您的浏览器收藏夹,一键直达永不失联!

Linux cut命令

linux系统 涛涛 66次浏览 0个评论

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>

欢迎转载本文:Linux cut命令
喜欢 (0)
[ld]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址