Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    See Useless use of cat? Commented Sep 25, 2023 at 7:15
  • 1
    @DavidC.Rankin: jq doesn't support editing files in place, and bash/sh disallows opening a file for reading and writing to it at the same time (it will truncate the file first), so the usage of cat in this context would be appropriate, otherwise you'd have to move files around and create multiple files, like his first example. Commented Jan 3 at 19:34
  • @LiamStanley absolutely. Your pattern is cmd original.file > tmp && mv -f tmp original.file I'm not sure how my comment above implied anything different? Commented Jan 4 at 5:11
  • @DavidC.Rankin I was implying that it's not a useless use of cat, and doesn't fall under the criteria of the linked post. Your follow-up solution does effectively the same thing, but is not more efficient, or necessarily better (and is already a part of the answer as one potential solution). Additionally, the mentioned solution using "mv" has side-effects -- permissions may not be the same to the new file, and it may change the fd for existing processes which already have the file open. Commented Aug 27 at 0:59