Sed replace pattern with line number

后端 未结 7 2214
南方客
南方客 2021-01-05 03:53

I need to replace the pattern ### with the current line number.

I managed to Print in the next line with both AWK and SED.

sed -n \"/###/{

7条回答
  •  臣服心动
    2021-01-05 04:36

    Following on from https://stackoverflow.com/a/53519367/29924

    If you try this on osx the version of sed is different and you need to do:

    seq 1 `wc -l FILE | awk '{print $1}'` | xargs --verbose -IX sed -i bak "X s/__line__/X/" FILE
    

    see https://markhneedham.com/blog/2011/01/14/sed-sed-1-invalid-command-code-r-on-mac-os-x/

提交回复
热议问题