sed in-place flag that works both on Mac (BSD) and Linux

后端 未结 13 2381
心在旅途
心在旅途 2020-11-22 08:18

Is there an invocation of sed todo in-place editing without backups that works both on Linux and Mac? While the BSD sed shipped with OS X seems to

13条回答
  •  广开言路
    2020-11-22 08:28

    The -i option is not part of POSIX Sed. A more portable method would be to use Vim in Ex mode:

    ex -sc '%s/alfa/bravo/|x' file
    
    1. % select all lines

    2. s replace

    3. x save and close

提交回复
热议问题