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*

3
  • Thanks a lot! Since I have multiple loops, I output sed -e result to a file for all the sed replacements I need to do. I then call this output file using sed -i -f tempSed.sed targetFile.txt . Currently the server is not under heavy load, yet, with my old approach it took 127.448 seconds, whereas with your suggestion it only takes 5.623 seconds. Running it locally the speed improvement was from 3.848s to 3.522s. Commented Aug 30, 2021 at 15:33
  • 1
    @a20, you can probably combine the multiple loops without needing a temporary file: (loop1; loop2; loop3) | sed -f -. (OTOH, if you like a file, then put it somewhere local, such as in "${TMPDIR:-/tmp}/"). Commented Aug 30, 2021 at 17:33
  • 1
    The best way to find a good local location for your file is to use tmpfile, of course (don't forget to set a trap so it's removed even if your script exits early). Commented Aug 31, 2021 at 7:04