tags:

views:

216

answers:

1

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?

+7  A: 

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
Daniel LeCheminant
just gonna shoot myself now... Thanks.
corymathews
@corymatthews: np; sometimes it just takes a second pair of eyes :]
Daniel LeCheminant