pablo
pablo

Reputation: 385

Gnuplotting the sorted merge of two CSV files

I am trying to merge and sort two CSV files skipping the first 8 rows.

I try to sort one of the files by the 36th column I use:

awk '(NR>8 ){print; }' Hight_5x5.csv | sort -nk36

and to merge the two files:

cat Hight_5x5.csv <(tail +8 Hight_5x5_b.csv)

The sort command it does not work.

I would like two use both actions in a command and send the result to the plot command of gnuplot. I have tried this line:

awk '(NR>8 ){print; }' (cat Hight_5x5.csv <(tail +8 Hight_5x5_b.csv)) | sort -nk36

and it does merge the two files but it does not sort by column 36, thus I assume in gnuplot plot command will not work too.

plot "<awk '(NR>8 ){print; }' (cat Hight_5x5.csv <(tail +8 Hight_5x5_b.csv)) | sort -nk36"

The problem is the format of the two files. The data have "," separations. For example, ...,"0.041","3.5","40","false","1000","1.3","20","5","5","-20","2","100000000","0.8",....

This link has the two CSV files.

Regards

Upvotes: 0

Views: 98

Answers (1)

karakfa
karakfa

Reputation: 67567

$ awk 'FNR>8' file1 file2 | sort -k36n 

should do, I guess you should be able to pipe to gnuplot as well.

Don't understand your comment, sort will sort. Perhaps you don't have 36 fields or your separator is not white space, which you have to specify.

Here is an example with dummy data with comma separated fields

$ awk 'FNR>3' <(seq 20 | paste - - -d,) <(seq 10 | shuf | paste - - -d,) | sort -t, -k2n
5,1
2,7
7,8
9,10
11,12
13,14
15,16
17,18
19,20

Upvotes: 1

Related Questions