2014-12-26 44 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

相關問題