I’m trying to pull some data out of logs on remote machines using awk, and have noticed that if I ssh into the machine and run
awk '{print $0}' /path/to/log.txt
I get the expected output (containing log messages, stack traces, etc.), but if I run
ssh host "awk '{print $0}' /path/to/log.txt"
then the output looks like the following:
0
1
0
0
1
1
1
1
1
1
Any ideas why this may be happening?
Escape the dollar sign.
Because the single quotes don’t protect the
$0on the local side, it gets substituted befor it’s sent to the remote side.You could also try:
That protects the
$0on the remote side, but it takes more changes to your command.