首页 > 解决方案 > `set datafile separator "|||"` 中的多字符分隔符不起作用

问题描述

我有一个输入文件example.data,其中有一个三重管道作为分隔符,第一列中有日期,最后一列中有一些或多或少不可预测的文本:

2019-02-01|||123|||345|||567|||Some unpredictable textual data with pipes|,
2019-02-02|||234|||345|||456|||weird symbols @ and commas, and so on.
2019-02-03|||345|||234|||123|||text text text

当我尝试运行以下 gnuplot5 脚本时

set terminal png size 400,300
set output 'myplot.png'

set datafile separator "|||"
set xdata time
set timefmt "%Y-%m-%d"
set format x "%y-%m-%d"
plot "example.data" using 1:2 with linespoints

我收到以下错误:

line 8: warning: Skipping data file with no valid points

plot "example.data" using 1:2 with linespoints
                                              ^
"time.gnuplot", line 8: x range is invalid

更奇怪的是,如果我将最后一行更改为

plot "example.data" using 1:4 with linespoints

然后它工作。它也适用于1:7and 1:10,但不适用于其他数字。为什么?

标签: command-linegnuplot

解决方案


使用时

set datafile separator "chars"

语法,字符串被视为一个长分隔符。相反,引号之间列出的每个字符都成为自己的分隔符。来自 [简纳特,2016 年]:

如果您提供显式字符串,则字符串中的每个字符都将被视为分隔符。

所以,

set datafile separator "|||"

实际上相当于

set datafile separator "|"

和一条线

2019-02-05|||123|||456|||789

被视为有十列,其中只有 1、4、7、10 列是非空的。


解决方法

找到其他一些不太可能出现在数据集中的字符(在下面,我将假设\t作为示例)。如果您无法使用不同的分隔符转储数据集,请使用sed替换|||\t

sed 's/|||/\t/g' example.data > modified.data # in the command line

然后继续

set datafile separator "\t"

modified.data作为输入。


推荐阅读