I'm trying to remove (non-consecutive) duplicate lines in a file I have loaded in vim (without sorting them). In several places on the web I've found the nugget
awk '!x[$0]++' as a pipe command that will do this, and indeed if I run this from my shell directly, i.e.
cat myfile | awk '!x[$0]++', it works as expected.
However, in vim, I've tried selecting some lines in line-wise visual mode, then typing
:'<,'>!awk '!x[$0]++', and I get an error of
cannot read file /tmp/nvimQFXXXX/31.
My guess would that in some way my syntax is not quite right, and maybe I need to somehow escape some of the characters? I've tried
\ to escape various characters though, and I can't figure it out. I've looked in the help, but I don't see anything about escaping characters.
Bonus points if you can wrap this up in a mapping and/or function; that's my end goal!