I've the following file (which is a simplification of the hosts file):126.0.0.1127.0.0.1128.0.0.1and I'm trying to invoke the following command:ex +g/127/d -cwq filewhich is supposed to remove lines consisting 127, then write and quit.It works when using vim -e, however it doesn't work using ex/vi.Although when printing buffer after the change, it seems the change has been made:ex +g/127/d|%p filebut it also displays the following warning:Badly formed addressI'm using original Ex v4.0 (gritter) 3/25/05. On OS X can be installed via brew install ex-vi.Why doesn't the above command work in ex editor? And how do I make it work?
Why aren't :g/X/d changes saved in Ex?
global command;ex command
There are some problems here. First ex is made for interactive use. You can't use several -c commands. Second, and this is a specialty of the :g command, you can't separate several commands using the '|'. A :g/127/d|wq command would write and quit after the first match)This makes it effectively useless to add another command after the -c command. What works however is this traditional approachcat <<EOF|ex /foobarg/127/dxEOFThis also works with nvi. Though, I could make nvi also use nvi -e +'g/127/d|wq' foobarbut that is also not portable. (I don't know, why this works, however).