【问题标题】:deleting a line of text from a document using terminal使用终端从文档中删除一行文本
【发布时间】:2018-01-02 05:31:48
【问题描述】:

所以在终端中,如果我创建一个文档然后添加一行文本,我应该使用什么命令从文档中删除该行文本?更多信息见下文:

touch test.doc 
echo "this is a test" >> test.doc 

现在,如果我想删除那一行(“这是一个测试”)的文本,我该怎么办?

【问题讨论】:

  • 您的iOS 设备上是否运行了终端?

标签: macos terminal scripting


【解决方案1】:
sed -i '$ d' test.doc
  • -i 表示直接修改文件,即test.doc
  • $ 表示最后一行
  • d 表示删除

sed 的基本思想是将动作与模式联系起来。 $ d 链接 delete 与模式 last line。您可以在sed manual找到更多详细信息。


  1. https://www.gnu.org/software/sed/manual/sed.html

【讨论】:

  • 我得到 sed: 1: "test.docx": undefined label 'est.docx'
猜你喜欢
  • 1970-01-01
  • 2014-04-21
  • 2013-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多