设置数据文件分隔符"|||"中的多字符分隔符不起作用 [英] multi-character separator in `set datafile separator "|||"` doesn't work

查看:188
本文介绍了设置数据文件分隔符"|||"中的多字符分隔符不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an input file example.data with a triple-pipe as separator, dates in the first column, and also some more or less unpredictable text in the last column:

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脚本

When I try to run the following gnuplot5 script

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

即使是陌生人,如果我将最后一行更改为

Even stranger, if I change the last line to

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

然后它起作用.它也适用于1:71:10,但不适用于其他数字.为什么?

then it works. It also works for 1:7 and 1:10, but not for other numbers. Why?

推荐答案

使用

set datafile separator "chars"

语法,将字符串视为一个长分隔符.取而代之的是,引号之间列出的每个字符将自己变成分隔符.摘自[Janert,2016]:

syntax, the string is not treated as one long separator. Instead, every character listed between the quotes becomes a separator on its own. From [Janert, 2016]:

如果您提供一个明确的字符串,则字符串中的每个字符都将是 视为分隔符.

If you provide an explicit string, then each character in the string will be treated as a separator character.

因此

set datafile separator "|||"

实际上等于

set datafile separator "|"

和一行

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

被视为具有十列,其中只有1,4,7,10列为非空.

is treated as if it had ten columns, of which only the columns 1,4,7,10 are non-empty.

解决方法

找到其他不太可能出现在数据集中的字符(在下文中,我以\t为例).如果无法使用其他分隔符转储数据集,请使用sed|||替换为\t:

Find some other character that is unlikely to appear in the dataset (in the following, I'll assume \t as an example). If you can't dump the dataset with a different separator, use sed to replace ||| by \t:

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

然后继续

set datafile separator "\t"

modified.data作为输入.

这篇关于设置数据文件分隔符"|||"中的多字符分隔符不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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