Try
ssh myuser@machine "awk -s '$(<my_local_awk_script.awk)' /remote/path/remote_file.txt"
This interpolates the exact contents of the local file as flat text into the string, so embedded single-quotes will likely cause it to explode.
My target system doesn't have the -s
option for awk
, so I couldn't test that.
My local file:
BEGIN{ print "Hello, " }
NR=1{print "World!"; exit; }
the output:
$: ssh sa-nextgen-jenkins.eng.rr.com "awk '$(<x)' x"
Hello,
World!
Safer - copy the file over and execute it, then delete if you need to.
$: scp x sa-nextgen-jenkins.eng.rr.com:~/x &&
> ssh sa-nextgen-jenkins.eng.rr.com "awk -f x .bash_profile && rm ~/x"
x
100% 56 0.7KB/s 00:00
Hello,
World!
so for you:
scp my_local_awk_script.awk myuser@machine:~/my_local_awk_script.awk &&
ssh myuser@machine "awk -s -f ~/<my_local_awk_script.awk /remote/path/remote_file.txt && rm ~/my_local_awk_script.awk"
Make sure you don't botch that and accidentally delete your local. You might want to put the remote in /tmp
, etc.