regex - 对特殊字符使用 sed

标签 regex linux bash sed command

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

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

最佳答案

这能解决您的问题吗?

➜  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

关于regex - 对特殊字符使用 sed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23500745/

相关文章:

regex - Go 中的 "Unknown escape sequence"错误

c - perf_event_open 不能打开超过 7 个 fd

c++ - SYSTEMTIME 等同于 linux

linux - 远程开发 - 在 Windows 上编辑并在 Linux 上构建

javascript - 使用javascript在字符串中查找电子邮件地址

正则表达式(re2 googlesheets)多行单元格中的多个值

regex - perl 正则表达式忽略特定关键字

bash - 具有多个范围和单词的curl批量下载

bash - 在 bash 脚本中查找本月的最后一个星期六

linux - 如何用逗号而不是空格分割列表