Hello,
I need to interact awk with an existing program (gcc-compiled) I wrote. This gcc-program takes arguments at the command line and returns a number.
More precisely, the arguments are listed in a text file ; I need awk to fetch the arguments, serve them as input to the gcc-program and , ideally, add the result to the text file in a new column.
The following example is deliberately simple. My actual gcc-program is more complicated and can't be converted to awk.
[root]# cat gcc_program.c
#include <stdio.h>
int main (int argc, char *argv[])
{
int i,j,sum;
i=atoi(argv[1]); /* cast argv[1] to integer i */
j=atoi(argv[2]); /* cast argv[2] to integer j */
sum=i+j; /* add both */
printf ("%d",sum); /*print sum on stdout */
return (0);
}
[root]#cat input.txt
2 4
4 8
1 4
I tried the following (after adding the current directory in PATH):
[root]# awk '{sum = gcc_program $1 $2} {print sum}' input.txt
24
48
14
It basically concatenates both arguments.
Does anyone have an idea? Thanks!!
Sibawe
I need to interact awk with an existing program (gcc-compiled) I wrote. This gcc-program takes arguments at the command line and returns a number.
More precisely, the arguments are listed in a text file ; I need awk to fetch the arguments, serve them as input to the gcc-program and , ideally, add the result to the text file in a new column.
The following example is deliberately simple. My actual gcc-program is more complicated and can't be converted to awk.
[root]# cat gcc_program.c
#include <stdio.h>
int main (int argc, char *argv[])
{
int i,j,sum;
i=atoi(argv[1]); /* cast argv[1] to integer i */
j=atoi(argv[2]); /* cast argv[2] to integer j */
sum=i+j; /* add both */
printf ("%d",sum); /*print sum on stdout */
return (0);
}
[root]#cat input.txt
2 4
4 8
1 4
I tried the following (after adding the current directory in PATH):
[root]# awk '{sum = gcc_program $1 $2} {print sum}' input.txt
24
48
14
It basically concatenates both arguments.
Does anyone have an idea? Thanks!!
Sibawe