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*

6
  • Note that (a) this is not fully POSIX compliant as ex is not mandated to support +command syntax, and also (b) it is very brittle if used in scripting as the non-existence of file2 will hang ex up waiting on user input. See my answer for a version that avoids these pitfalls. Commented Jan 3, 2018 at 1:32
  • @alhelal Sure. Does it make sense now? Commented Jan 3, 2018 at 1:56
  • Good edit, but just FYI it is still not script-worthy. If file2 is not readable ex will still wait forever. If ex is unable to write the changes to file1 it will wait forever. Any error will make ex wait for user input. For a scripted use of ex, you should never do otherwise than feeding it commands in a way that guarantees it will receive an EOF (such as using a pipe or heredoc). Commented Jan 3, 2018 at 2:22
  • Do you add a "not POSIX compliant" comment to every answer that's not POSIX compliant. Because the convention I've noticed is the inverse: the person posting the answer indicates POSIX compliance. You can assume the rest aren't. I'm thinking of that "o"-word again. Commented Jan 3, 2018 at 2:27
  • Unless it's stated in the answer that it's not portable, or unless (even better) it's stated on which specific systems the command works, then yes, I usually do. If you say, "on Linux systems" or "using GNU Awk" or similar, then obviously you don't need to say it's not POSIX-compliant. I picked up the habit from this site of being very specific about where a command will or will not work—and it's saved me a lot of trouble, so I do such comments myself just as I've seen others do. Feel free to ping me in chat; let's not clutter up the comments. Commented Jan 3, 2018 at 2:48