I'm trying to move a certain ViM command into a Linux Bash script. In ViM the command is
:g/^SOMEWORD$/d
To delete any lines containing only some word and nothing else.
When I move it into a bash script it doesn't work anymore
vim -e -s /tmp/file.txt << EOF
:g/^SOMEWORD$/d
:update
:quit
EOF
Escaping the $
doesn't seem to make a difference, is there another way to use the $
in this type of scenario or am I missing something else?
vim -e -s /tmp/file.txt << EOF
:g/^SOMEWORD\$/d
:update
:quit
EOF
$
works for me (perhaps because/d
isn't a legal variable name?). Replacingvim -e -s /tmp/file.txt
with a simplecat
confirms the$
is being passed through the heredoc$
? if you run the script without the$
does it then delete lines containing SOMEWORD anywhere on the line?EOF
it will avoid interpretation/evaluation of things that look like variables. Sovim -e -s /tmp/file.txt << 'EOF'
. Please try this and see if it helps. (At any event it will avoid the need for\$
instead of$
.)