We know that we can run commands from vim using :!command <args>
. For example:
:%!awk '{ print $2,$1,$3 }' FS=',' OFS=','
:%!sort
I am having trouble running an awk
script within vim. I can run the script from another terminal like this:
awk -f denorm.awk processed_l1.csv > processed_l2.csv
I get the following error for running (:!awk -f denorm.awk
) from vim:
awk: fatal: can't open source file `denorm.awk' for reading (No such file or directory)
shell returned 2
And when I give absolute path to the file denorm.awk
. Then empty screen pops up, no errors!
So how can I run this awk
script from vim?
I would prefer to continue in the existing csv file. This will allow me to revert back in case I make any mistakes.
:pwd
? When using a relative path, awk assumes the path is relative to the current directory. Also, as far as keeping the existing csv, you should use the filter syntax (:%!awk -f script
)/home/user/
; and I unknowingly missed the%
symbol in:%!awk
. That's why after processing, the results are not shown on screen.