'gawk -v RS='"' '...
is not a string that contains RS='"'
. It's equivalent to
gawk -v RS="' '...
The shell doesn't know that you want the entire string between the first and last '
should be treated literally; it reads from the first '
until the next '
, then continues parsing.
Further, there's no way to quote a single quote inside '...'
, as the backslash itself is taken literally. '\''
is not a single '
; it's '
and \
.
If you are using bash
or a shell with a similar extension, you can use ANSI-style quoting. You'll have to ensure that all literal '
and '\
are escaped.
# Should be correct, not not tested
ssh <HOST> $'gawk -v RS=\'"\' \'NR % 2 == 0 { gsub(/\\n/, "") } { printf("%s%s", $0, RT) }\' "<File name>" | wc -l'
Or you can use "..."
as the outer quotes, and ensure all literal $
and "
are escaped (as well as any \
that would otherwise be treated as an escape character).
# Should be correct, not not tested
ssh <HOST> "gawk -v RS='\"' 'NR % 2 == 0 { gsub(/\n/, \"\") } { printf(\"%s%s\", \$0, RT) }" "<File name>" | wc -l'
My preference would be to avoid the problem by putting your code in a script
#!/bin/sh
gawk -v RS='"' 'NR % 2 == 0 { gsub(/\n/, "") } { printf("%s%s", $0, RT) }' "<File name>" | wc -l
copying that to the remote host
scp <HOST>:\~/myscript
and executing it
ssh <HOST> 'sh myscript'