Gnuplotting the sorted merge of two CSV files

橙三吉。 提交于 2019-12-31 05:10:01

问题


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


回答1:


$ 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


来源:https://stackoverflow.com/questions/53502806/gnuplotting-the-sorted-merge-of-two-csv-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!