2014-12-26 104 views
0

这是我几天以来遇到的一个问题。我想通过做简单的脚本来简化很多工作..但脚本工作不正常。文件夹中的许多文件的Bash + gnuplot脚本

脚本应该做的事:

  1. 尾3行的文件中指定的目录$ {} FOLDER
  2. 变化extenstion从.gplt无法比拟的。
  3. 使用gnuplot函数绘制输出。

所有文件在这些文件夹开始:

set term postscript color 
set output "x_101.ps" 
plot "-" title "magU" with lines 
0 0 
5.00501e-06  0.00301606 
1.001e-05 0.00603211 
... 

所以我坚持这一点,一些部分没有工作,这就是为什么我问你们,如果有人可以看看对此:

#!/bin/bash 

rename(){ 
newname = $(basename .gplt) 
} 

FOLDER=(
~/Dokumenty/mgr/obliczenia_OF/ReConst/H20_ReConst_v1/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/H20_ReConst_v2/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/H20_ReConst_v3/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/H20_ReConst_v4/postProcessing/sets/* 

~/Dokumenty/mgr/obliczenia_OF/ReConst/R134_ReConst_v1/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/R134_ReConst_v2/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/R134_ReConst_v3/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/R134_ReConst_v4/postProcessing/sets/* 


~/Dokumenty/mgr/obliczenia_OF/ReConst/OM_ReConst_v1/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/OM_ReConst_v2/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/OM_ReConst_v3/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/ReConst/OM_ReConst_v4/postProcessing/sets/* 

~/Dokumenty/mgr/obliczenia_OF/PeConst/R134_PecletConst_v1/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/R134_PecletConst_v2/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/R134_PecletConst_v3/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/R134_PecletConst_v4/postProcessing/sets/* 

~/Dokumenty/mgr/obliczenia_OF/PeConst/OM_PecletConst_v1/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/OM_PecletConst_v2/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/OM_PecletConst_v3/postProcessing/sets/* 
~/Dokumenty/mgr/obliczenia_OF/PeConst/OM_PecletConst_v4/postProcessing/sets/* 
) 

for file in *; do 
    tail -n+3 ${file} >> ${file} 
done 

for ff in *; do 
rename ${ff} 
done 

for f in *; do 
gnuplot <<- EOF 
set terminal png size 400,250 
set output '${f}.png' 
set grid 
set xlabel 'y' rotate by 360 
set ylabel 'U(y)' 
plot "${f}" using 2:1 with lines 
EOF 
done 

PS。还有一件事。该文件夹有子文件夹,为什么我用这个:

sets/* 

在最后,我担心它可能是错误的。

干杯 jilsu。

+0

'tail -n + 3'给出(包括)行号3的所有行..这是正确的吗? –

+0

那么你想要做的是改变所有'.gplt'文件,使得它们产生一个'.png'而不是一个postscript文件?但是你想保留原始的'.gplt'文件? –

回答

2

您没有使用FOLDER任何地方。您继续在循环中使用*。你想在你的循环中使用"${FOLDER[@]}"

rename功能语法无效。外壳分配线不需要=周围的空间。所以它需要是newname=$(basename .gplt),但这只是分配一个变量而不实际重命名任何文件。

你也可能不需要那么rename功能,如果你想要的是在输出gnuplot呼吁改变file.gpltfile.png。您可以改为在HEREDOC中使用$(basename "$f" .gplt)

1

似乎有是几个问题:

末带*的做法是行不通的,发现使用替代。

find ${FOLDER[i]} -type f 

我不知道你想达到什么一个:

tail -n+3 ${file} >> ${file} 

它的作用是复制$文件的内容,从3号线开始什么(要附加到你读取文件从)。

+0

谢谢你的回答。这很有帮助。 – jilsu

相关问题