Remotely executing awk command

ssh user@machine awk '{ split ($1,ar,"!");print ar[2]}' samp >samp1

Error:
Unmatched '.

However on <machine> awk '{ split ($1,ar,"!");print ar[2]}' samp >samp1
executes successfully.

Any suggestions.

You need to escape the various control characters so that the string remains faithful as it goes between machines.

Alternatively pipe the command in as the stdin input rather than on the commmand line.