【问题标题】:cut function on specific line特定行上的剪切功能
【发布时间】:2021-12-01 14:48:30
【问题描述】:

我在unix中有一个文件,如下所示:
$ cat file
1.this is the test file.
The file have data related to recent survey.

要求是仅从第一行剪切前两个字符并按原样打印文件的其余内容,我已经尝试了相同的剪切命令..

$ cut -c 3- file
this is the test file.
e file have data related to recent survey.

但是它从每行中删除了 2 个字符,有没有办法只在第一行或任何其他我们可以用来获得所需结果的命令上实现剪切(前两个字符也可以是任何需要删除,不是特别是 1.)

【问题讨论】:

    标签: unix cut


    【解决方案1】:

    使用 shell 实用程序 headtailcut

    head -n1 file | cut -c3-; tail -n+2 file
    

    sed one-liner:

    sed '1s/..//' file
    

    【讨论】:

      猜你喜欢
      • 2021-01-08
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-22
      相关资源
      最近更新 更多