【问题标题】:Using sed on a special character [duplicate]在特殊字符上使用 sed [重复]
【发布时间】:2014-05-06 17:05:00
【问题描述】:

目前我有一个文件 包含文本 Your path: ../test/tester [hello] whatever 但我想把它改成:Your path: ../../tested/text [hello] whatever 我试过 sed 但我相信 ../ 是一个特殊字符,所以我不太确定如何解决这个问题。

这对我不起作用。
seds/tester/..//g;s/tester/tested/text/

【问题讨论】:

  • 使用不同的分隔符。
  • 我遵循了该指南,但我仍然得到错误的替换 sed "s|\test|${../tested}|"我的文件
  • 不确定你在尝试什么,但像s|../test/tester|../../tested/text| 这样的东西会起作用。
  • ${../tested} 没有任何意义,它会导致错误。也许你想说../${tested}
  • 你为什么要在模式中转义testsed "s|test|../${tested}|" myfile

标签: regex linux bash sed command


【解决方案1】:

这能解决您的问题吗?

➜  scripts  cat example
Your path: ../test/tester [hello] whatever

➜  scripts  sed "s|../test/tester|../../tested/text|" example > example2
➜  scripts  cat example2
Your path: ../../tested/text [hello] whatever

【讨论】:

    猜你喜欢
    • 2019-10-14
    • 1970-01-01
    • 2019-05-12
    • 2018-11-09
    • 1970-01-01
    • 2012-09-09
    • 2019-05-14
    • 1970-01-01
    • 2011-05-17
    相关资源
    最近更新 更多