user1993416
user1993416

Reputation: 768

Merge two CSV files in a Gnuplot script

This question is a continuation of How to run a shell command in Gnuplot and place the output in new file and the example is the same.

In that question, it is answered how to take a CSV file with each data separated by "," and, remove those characters from the row 8th and, after that, sort the result by the 36th column values.

I have tried the solution, for example,

`tail -n+8 Hight_6x6.csv | tr '",' ' ' | sort -nk36`

and works fine.

Now, I would like to make the same but with the merged result of two similar CSV files. That is, take the two files from the 8th row, append one to the other and sort by column 36th.

The following line

`cat 2x2/Hight_2x2.csv <(tail +8 2x2b/Hight_2x2_b.csv) | tail -n+8  | tr '",' ' ' | sort -nk36`

makes what I want to do in the Terminal but it gives an error in Gnuplot. The error tells that there is an unexpected '(' character. The two files to merge are in different subdirectories (2x2 and 2x2b) from where I run the script. The CSV files are in this link.

Regards

Upvotes: 1

Views: 240

Answers (1)

meuh
meuh

Reputation: 12255

To avoid having to escape single or double quotes, you can use a third form of quoting, the here-document to create a datablock. You can then pipe the datablock into a bash command:

$datablock << EOD
cat a.csv <(tail -n+2 b.csv) | tail -n+8  | tr '",' '  ' | sort -nk36 >pe_H_6x6.txt
EOD

set print "|bash -x"
print $datablock
set print

The -x here is just to check the command that gets executed.

Upvotes: 3

Related Questions