I need to substitute a portion of an awk command in a script with different cases, from this:
CONTAINER=$1
RESULTS=$(ssh -o LogLevel=QUIET -t -i ~/key.pem user@server sudo docker stats --no-stream $CONTAINER | awk '{if (NR!=1) {print substr($2, 1, length($2)-1)}}')
to this:
#!/bin/bash
CONTAINER=$1
TYPE=$2
case "${TYPE}" in
cpu)
AWK="'{if (NR!=1) {print substr($2, 1, length($2)-1)}}'"
;;
esac
RESULTS=$(ssh -o LogLevel=QUIET -t -i ~/key.pem user@server sudo docker stats --no-stream $CONTAINER | awk $AWK)
But I always get a syntax error.