4 ms·
> Watch out, that's a Linux-ism and macOS's sed It's GNU sed vs (Free)BSD sed, which are different enhancements of the POSIX standards for sed that went in dif
by ancientsofmumu 4y ago
> Watch out, that's a Linux-ism and macOS's sed
It's GNU sed vs (Free)BSD sed, which are different enhancements of the POSIX standards for sed that went in different design directions. One could Homebrew/macports install gnu-sed on macOS to get a GNU version to write Linux-portable scripts as-needed.
- deleted 4y ago[deleted]
- 1vuio0pswjnm7 4y agoPlan9 sed has no -i option. Older versions of NetBSD will not have it either. I never understood the point of the -i option other than to conserve keystrokes. A temporary file is still created then removed; the -i option only saves the user from having to specify it. Maybe the intent is it is only for "one-off" use, not for use in scripts. This will work for GNU, BSD and Plan9: sed -n 's/old/new/wfile.tmp' file mv file.tmp file Or just use redirection. Given the choice between avoiding some keypresses and more portable scripts, I will keep choosing the later. NetBSD sed may have the -i option now but I do not see anyone using it in scripts meant to be portable, like build.sh^1 1. https://ftp.netbsd.org/pub/NetBSD/NetBSD-release-9/src/build.sh https://ftp.netbsd.org/pub/NetBSD/NetBSD-release-9/src/build...
- mdaniel 4y agoYeah, I've heard that argument, too, but I fear that ship has sailed Also, be aware you currently have duplicated comments: https://news.ycombinator.com/item?id=31254181 https://news.ycombinator.com/item?id=31254181
- jwilk 4y ago> sed -n 's/old/new/wfile.tmp' file This saves only lines which underwent substitution, which was probably not what you wanted.
- 1vuio0pswjnm7 4y agoMissing semicolon. sed -n 's/old/new/;w file.tmp' file Unlike BSD and GNU sed, it appears that Plan9 sed will append to instead of overwite file.tmp It also requires a space after the w command.
- ttyprintk 4y agosed -i alone overwrites a soft or hard link with the contents of the file.
- 1vuio0pswjnm7 4y ago-i creates a temporary file and then replaces the original with the temporary. The BSD man page advises not to use -i alone because if there is insufficient space to store the temporary, data may be lost.