command-line - `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:7
and 1:10
,但不适用于其他数字。为什么?
解决方案
使用时
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
作为输入。
推荐阅读
- angularjs - 为什么使用 AngularJS 在 HTML 页面中显示 JSON 答案的 {{variable_name}} 不起作用?
- html - css中的过渡/动画后元素不需要的小移动
- docker - 在 docker 中构建 rust 项目会导致 Cargo 无法下载依赖项
- javascript - 如何从 href 属性获取宽度和高度
- php - PDO 没有将 MS Access DB 的输出发送到 php
- mongodb - MongoDB多组聚合
- php - AuthnetWebhook 包签名密钥验证
- json - 如何在 Sql server 中替换 JSON 对象中的完整对象
- javascript - 如何为 Canvas 上动态添加的形状添加动态标签?
- python - Python:如何在文件中每秒打印 datetime.datetime.now()?