I have a small piece of c code which should run an awk command on my linux machine. However for the life of me it will not exec. The awk works if I directly run it in the terminal.
My current failed command
system("awk '{ printf \"%d \n\", $12 }' results.dat | sort -n");
It fails with
awk: { printf "%d
awk: ^ unterminated string
How else do you escape the double quotes so that the command will run? Also why does this fail, but when I replace the system call with a printf it will print?
Perhaps you should escape the \\n
again, as in
system("awk '{ printf \"%d \\n\", $12 }' results.dat | sort -n");
// ^ note the extra \
as I think the \\n
is meant to be part of the printf
.
Your current construction calls system
with an argument of
awk '{ printf "%d
", $12 }' results.dat | sort -n
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.