我在 gnuplot 中使用 for 循环根据搜索命令的输出绘制多个文件。 plot 命令将整个文件名放入 key 中,包括完整路径。我只想放文件名,删除目录路径。这可能吗?
#!/usr/bin/gnuplot -persist
set terminal pdfcairo enhanced size 10in,7in
wmax_List = "`echo $(ls E0025/4D/Re2000/NS.dat.*[02468]000)`"
plot for [i in wmax_List] i using 1:2 with points title i
在这种情况下,所有文件都在同一个文件夹中。 title i
选项使 "E0025/4D/Re2000/" 出现在情节关键的每一行中。我可以将绘图脚本放在该文件夹中,但那里有数千个数据文件(我实际上是每 1000 个绘制一个),所以我更愿意在当前位置执行脚本。
所以,我的问题是,有没有办法从 key 中删除完整路径?我尝试使用 find
而不是 ls
来生成仅包含文件名的字符串列表,但我不知道如何将完整路径 + 字符串放在图中命令。
谢谢
最佳答案
你有不同的可能性:
dirname = 'E0025/4D/Re2000/'
wmax_List = system('ls '.dirname.'NS.dat.*[02468]000')
ind = strlen(dirname)+1
plot for [i in wmax_List] i using 1:2 with points title i[ind:*]
或
plot for [i in wmax_List] i using 1:2 with points title system('basename '.i)
关于plot - 删除 gnuplot 自动标题键标签中的文件路径,只留下文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19642724/