News for hackers. Stuff that matters.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by 1vuio0pswjnm7 on Tuesday May 03, 2022 @06:06PM (#31254224)
Plan9 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...

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by mdaniel on Tuesday May 03, 2022 @06:26PM (#31254396)
Yeah, 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

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by jwilk on Wednesday May 04, 2022 @02:02AM (#31257198)
> sed -n 's/old/new/wfile.tmp' file

This saves only lines which underwent substitution, which was probably not what you wanted.

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by 1vuio0pswjnm7 on Wednesday May 04, 2022 @02:24AM (#31257337)
Missing 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.

Re:Bash-oneliner: A collection of handy Bash one-liners and ... by ttyprintk on Wednesday May 04, 2022 @02:30AM (#31257379)
sed -i alone overwrites a soft or hard link with the contents of the file.
Re:Bash-oneliner: A collection of handy Bash one-liners and ... by 1vuio0pswjnm7 on Wednesday May 04, 2022 @03:56AM (#31257862)
-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.