Execute sed / awk script in VIM
Recently I had a need to use an AWK script within VIM. It was going to be the easiest way to accomplish the task at hand – just a simple one-liner awk statement. I got pretty frusterated as I had not done this in awhile and spent a few minutes too long looking for how to do this. So for future reference here it is:
{range}!{filter}
For example: From VIM command mode (this will print the last field of each line)
:%!awk '
{ print $NF }'
An important note … Remember when using sed / awk and vim to always keep your own cheaat sheet handy. Re-using a command you have done before saves an incredible amount of time and frustration. It’s a big reason I have started this site!