objective:
/^Mar find a pattern, (line starts with Mar) GN find last occurrence of this pattern dgg delete from current position to top of file :wq write and quit
I've tried:
vi -c /^Mar -c GN -c dgg -c wq testfile.log
it complains GN is not an editor command dgg is not an editor command
yet when I issue the same within vi, they work just fine. I'm hoping I'm just missing something simple, but I've been searching on Google for ages, and just can't ask the right question, apparently.
Thanks!
The commands you provide after the -c switch are interpreted as Ex commands, which means e.g.
-c GN will behave as if running :GN inside vim. Prepend "normal" to the command in order to interpret it in normal mode:
vi -c "/^Mar" -c "normal GN" -c "normal dgg" -c wq testfile.log
The commands written in the command line are ex commands. They are commands that are prefixed by ":" in when working with vim. You can rewrite your command line to use ex commands:
vi -c '/^Mar' -c '$' -c '?' -c '1,.d' -c 'wq' testfile.log
That should does bas-ically the same as reuired - find the pattern, goto last line, find the pattern backward, delete everything from begin to current line, write and quit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With