My folder structure looks kind of like this
$ tree
.
├── Original_folder
│ └── cat.txt
├── folderCD
│ └── cat.txt
├── folderGK
│ └── cat.txt
├── folderFE
└── cat.txt
Each cat.txt file has 5 line before starting the column header. Sample cat.txt file is like this
Version LRv1.10.0
Build date 2017-12-06
MOL-calc
PRESSURE
!
Time[s] InletT[K] InletP[Pa] O2_GasOut C_GasOut
100 0.000885 1000000 0.0007 0.2111
and so on....
I want to plot first column along with the column which have column header with a keyword "_GasOut". (There are unknown number of header with this keywords, For each column I would like to have a separate graph). Additionally, the graphical results of Original_folder should be plotted in the same graph for all the plots from folderCD, folderGK, folderFE...... and so on.
Corresponding graph should be saved in the corresponding folders with a title same as column header. In each graph there should be two legend one is "original_folder" and another is "folderCD/folderGK/......"
I got all the output plot commands for Original_folder in one txt file and plot commands for all the other folders into another txt file. After that I am not finding a way to go ahead.. How can I do this for all other cases ? And how to make the column header as title?
LATEST UPDATE
for dir in folder* ; do
echo "Preparing Post_processing files for ${dir}"
mkdir "$dir"/Post_processing
gawk -F $'\t' '
/_GasOut/{
for(f=1;f<=NF;f++){
hdr=$f
colhdr[f]=hdr
if(index(hdr,"_GasOut"))wanted[f]=1
}
}
ENDFILE{
print "reset\nset terminal pngcairo size 1024,768\nset encoding utf8\nset termoption dash\nset termopt enhanced"
print "set key top right"
print "set xlabel '"'Time[s]'"';"
for(f in wanted){
if(length(cmds)) cmds = cmds ",\n"
hdr = colhdr[f]
gsub(/^[[:space:]]+|[[:space:]]+$/,"",hdr)
printf("set ylabel '"'%s'"';\n",hdr)
printf("set output '"'"$dir/Post_processing"/%s.png'"'\n",hdr)
cmds = cmds "plot ""\"" FILENAME "\" using 1:" f " with lines" ","
#print "plot " FILENAME using 1:" f " with lines" ",""
cmds=cmds"'"'Original_folder/cat.txt'"' using 1:" f " with lines"
}
delete wanted
}
END{
print cmds
}
' "$dir"/cat.txt>"$dir"/plot.gpl
gnuplot "$dir"/plot.gpl
done
Current output is like this
reset
set terminal pngcairo size 1024,768
set encoding utf8
set termoption dash
set termopt enhanced
set xlabel 'Time[s]';
set ylabel 'H2_GasOut';
set output 'folderCD/Post_processing/H2_GasOut.png'
set ylabel 'O2_GasOut';
set output 'folderGK/Post_processing/O2_GasOut.png'
set ylabel 'H2O_GasOut';
set output 'folderFE/Post_processing/H2O_GasOut.png'
plot "folderCD/cat.txt" using 1:28 with lines,'Original_folder/cat.txt' using 1:28 with lines,
plot "folderGK/cat.txt" using 1:29 with lines,'Original_folder/cat.txt' using 1:29 with lines,
plot "folderGK/cat.txt" using 1:30 with lines,'Original_folder/cat.txt' using 1:30 with lines
Desired output
reset
set terminal pngcairo size 1024,768
set encoding utf8
set termoption dash
set termopt enhanced
set xlabel 'Time[s]';
set ylabel 'H2_GasOut';
set output 'folderCD/Post_processing/H2_GasOut.png'
plot "folderCD/cat.txt" using 1:28 with lines,'Original_RedKinMec/cat.txt' using 1:28 with lines,
set ylabel 'O2_GasOut';
set output 'folderGK/Post_processing/O2_GasOut.png'
plot "folderGK/cat.txt" using 1:29 with lines,'Original_folder/cat.txt' using 1:29 with lines,
set ylabel 'H2O_GasOut';
set output 'folderFE/Post_processing/H2O_GasOut.png'
plot "folderGK/cat.txt" using 1:30 with lines,'Original_folder/cat.txt' using 1:30 with lines
It's also good to have an output like this
set terminal pngcairo size 1024,768
set encoding utf8
set termopt dash
set termopt enhanced
set key top right
set xlabel "Time[s]"
set ylabel "O2_GasOut"
set output "Post_processing/O2_GasOut.png"
plot "folder1/cat.txt" using 1:22 with lines,\
plot "folder2/cat.txt" using 1:22 with lines,\
plot "folder3/cat.txt" using 1:22 with lines,\
plot "folder4/cat.txt" using 1:22 with lines
set ylabel "H2O_GasOut"
set output "Post_processing/H2O_GasOut.png"
plot "folder1/cat.txt" using 1:23 with lines,\
plot "folder2/cat.txt" using 1:23 with lines,\
plot "folder3/cat.txt" using 1:23 with lines,
plot "folder4/cat.txt" using 1:23 with lines
set ylabel "H2_GasOut"
set output "Post_processing/H2_GasOut.png"
plot "folder1/cat.txt" using 1:24 with lines,\
plot "folder2/cat.txt" using 1:24 with lines,\
plot "folder3/cat.txt" using 1:24 with lines,\
plot "folder4/cat.txt" using 1:24 with lines
N.B: folder numbers are not fixed.
I added one of the cat.txt file for reference. https://1drv.ms/t/s!Aoomvi55MLAQh1wMmpnPGnliFmgg