sed use: expected context address

后端 未结 2 1870
情书的邮戳
情书的邮戳 2021-02-01 10:49

I use the sed command on macOS with the following text:

$ cat pets.txt 
This is my cat
  my cat\'s name is betty
This is your dog
  your dog\'s name         


        
2条回答
  •  自闭症患者
    2021-02-01 11:18

    Mac OS X uses BSD sed and not GNU sed.

    When you use a GNU sed extension with Mac OS X sed, you get different results, or failures.

    Classically, sed does not support numeric offsets, forwards or backwards. You'll need to revise your script to work on Mac OS X.

    This would work on the given data, but the use of fish is suspect:

    sed '/dog/,/your fish/s/^/# /g' pets.txt
    

提交回复
热议问题