Have sed make substitute on string but SKIP first occurrence

前端 未结 3 1030
耶瑟儿~
耶瑟儿~ 2020-12-17 15:52

I have been through the sed one liners but am still having trouble with my goal. I want to substitue matching strings on all but the first occurrence of a line. My exact usa

3条回答
  •  孤城傲影
    2020-12-17 15:54

    You can avoid the problem with g and n

    Replace all of them, then undo the first one:

    sed -e 's/ /\\ /g' -e 's/\\ / /1'
    

    Here's another method which uses the t branch-if-substituted command:

    sed ':a;s/\([^ ]* .*[^\\]\) \(.*\)/\1\\ \2/;ta'
    

    which has the advantage of leaving existing backslash-space sequences in the input intact.

提交回复
热议问题