【问题标题】:Replace a word that has a specific format with another format用另一种格式替换具有特定格式的单词
【发布时间】:2021-12-25 18:04:04
【问题描述】:

我想将 c 和 2 ('C 2',) 之间的空格替换为两个空格作为 'C 2',我尝试使用 sed -i 但它不起作用 sed -i 's/'C 2',/'C 2',/g' test.dat

【问题讨论】:

    标签: linux


    【解决方案1】:

    引号停止引用。更改引用或转义它。

    你可以这样做:

    sed -i 's/'\''C 2'\'',/'\''C  2'\'',/g' test.dat
    

    '\'' 停止引用,转义单引号,然后继续引用。

    但对于您的具体情况,您可以只使用双引号:

    sed -i "s/'C 2',/'C  2',/g" test.dat
    

    【讨论】:

      猜你喜欢
      • 2021-10-17
      • 1970-01-01
      • 2021-08-05
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 2011-03-17
      • 2016-10-09
      相关资源
      最近更新 更多