在Gnuplot脚本中合并两个CSV文件 [英] Merge two CSV files in a Gnuplot script

查看:94
本文介绍了在Gnuplot脚本中合并两个CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是

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.

在该问题中,将回答如何获取一个CSV文件,并用","分隔每个数据,然后从第8行中删除这些字符,然后,按第36列的值对结果进行排序.

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`

工作正常.

现在,我想做同样的事情,但是要合并两个相似的CSV文件的结果.也就是说,从第8行获取两个文件,将一个附加到另一个,然后按第36列进行排序.

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.

以下行

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

做出了我想在终端中执行的操作,但是它在Gnuplot中给出了错误. 该错误表明存在意外的'('字符. 要合并的两个文件位于运行脚本的不同子目录(2x2和2x2b)中. CSV文件位于此链接中.

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.

致谢

推荐答案

为避免转义单引号或双引号,可以使用第三种形式的引号,即 here-document 创建一个数据块.然后,您可以将数据块通过管道传送到bash命令中:

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

此处的-x仅用于检查要执行的命令.

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

这篇关于在Gnuplot脚本中合并两个CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆