No idea about expect. But generally, during multiple program interaction you need to escape the special characters so that they can be ignored by the first program (expect engine in your case).
try awk \'{print $5}\'
You might also need to escape the "{","}" and even "$" if its a keyword in expect
I am not completely sure but you can try this.
Enclosing characters in single quotes preserves the literal value of
each character within the quotes. A single quote may not occur between
single quotes, even when preceded by a backslash.
-- excerpt from man bash
So you will need to find another method of using an awk program without using the single quotes -- perhaps making it available on the remote machine. Another possibility is to enclose the long string in double quotes. The "embedded" double quotes can be escaped and single quotes would be OK inside double quotes:
Script in a file works but expect -c still doesn't work.
---------- Post updated at 01:00 AM ---------- Previous update was at 12:52 AM ----------
It would be great if some one could help me out to accomplish this with a single command. That is by using expect -c. I would need to use many of these commands in my script. Giving seperate expect file for each expect command would be a hassle.
Chubler_XL's one line solution should work. Another way to do it is change each of the two single quotes in you original code to
'"'"'
That's sq1 dq sq2 dq sq3. With single quotes, there is no escaping. The only way is to end it with a matching single quote. Here the sq1 and sq3 are to end the previous and start the next part. dq sq2 dq (or you can also use backslash single quote) is the real single quote for the awk.