sed,插入完全字符串无意义

时间:2013-01-03 08:46:30

标签: regex sed

以前没用过sed,所以请和我一起出去。

我正在尝试使用sed将(-i)一行精确的代码插入到文件中。这是要插入的行:

  

“Sometext”。 $ index ++。 “\ t”。 'dummytext'。 “\ t” 的'\

这是我尝试过的(shell脚本):

sed -i '66 i\"Sometext" . $index++ . "\t" . 'dummytext' . "\t"' filename

这是文件名中的结果:

  

“Sometext”。 $ index ++。 “”。虚拟文本。 “”

应该是:

  

“Sometext”。 $ index ++。 “\ t”。 'dummytext'。 “\ t” 的

显然有些字符被sed解释为sed命令,我想避免这种情况。

请记住以上示例的指针/提示/提示吗?

TIA -HF

1 个答案:

答案 0 :(得分:1)

一些额外的逃脱和引用:

sed -i '2 i\"Sometext" . $index++ . "\\t" . '\''dummytext'\'' . "\\t"' filename