Search code examples
awkgnuplotpaste

gnuplot5 - sh: 1: Syntax error: "(" unexpected with awk


I am trying to use paste in combination with awk inside gnuplot so that I can take certain columns of two different files and plot the result. However, I am getting this error:

sh: 1: Syntax error: "(" unexpected

I understand that it's unhappy with that part of my gnuplot script:

system("paste <(awk '{print $1,$2,$3,$4,$5,$14}' ".filename(i).") <(awk '{print $14}' ".filename_without.")  > Tim_res_".i)

And more specifically the brackets before awk. Replacing the filenames without using a variable name doesn't work either while all the command works perfectly fine outside of gnuplot. If I remove the brackets, then it says it doesn't recognise awk, and the command doesn't work outside of gnuplot either.

I've read that adding #!/usr/bin/bash might help, but it actually doesn't solve the problem nor does it give another error message. I've never had this kind of problem using such commands within gnuplot before. I have a lot of files to plot in a similar way, hence why I'd like to make it automatic directly in gnuplot, the system command being only here to make sure it works before I can replace it directly after the plot command of gnuplot.

Thanks for any help


Solution

  • mklement0 has explained what the issue is - a workaround would be to avoid process substitution entirely:

    awk 'NR == FNR { col[NR] = $14; next } { print $1,$2,$3,$4,$5,$14,col[FNR] }' file2 file1
    

    That is, read the second file first and save the column, then do the "paste" yourself in awk.

    Moving the awk command to gnuplot:

    system("awk 'NR == FNR { col[NR] = $14; next } \
    { print $1,$2,$3,$4,$5,$14,col[FNR] }' " . filename_without . " " . filename(i))