【问题标题】:Unix command to copy last line of file to another fileUnix命令将文件的最后一行复制到另一个文件
【发布时间】:2011-05-19 17:53:56
【问题描述】:

请提供一个命令以通过获取另一个文件的最后一行来附加现有文件。

【问题讨论】:

    标签: file unix command


    【解决方案1】:
    tail -n 1 $file1 >> $file2
    

    虽然大多数系统也支持

    tail -1 $file1 >> $file2
    

    【讨论】:

    • tail -n 1 是正确的 POSIX 语法,应避免使用 tail -1
    【解决方案2】:
    tail $file1 -n 1 >> $file2
    

    或者,

    tail -1 $file1 >> $file2
    

    如果您希望它与 sudo 一起使用:

    tail -1 $file1 | tee -a $file2
    

    【讨论】:

      猜你喜欢
      • 2019-05-27
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 2021-12-20
      相关资源
      最近更新 更多