Hello,
I allow me to writing here to seek your assistance about my script bash !
I have many csv files that looks like :
MO2PPC20,60,1.5,4
MO2PPC20,39,0.3,5
MO2PPC20,105,2.0,4
MO2PPC20,91,2.0,4
MO2PPC20,79,0.4,4
MO2PPC20,62,1.2,3
MO2PPC20,69,0.3,4
MO2PPC20,60,0.6,4
MO2PPC20,60,1.2,4
MO2PPC20,12,0.5,1
MO2PPC20,130,1.5,11
MO2PPC20,180,0.5,3
The first column is the name of my frame, the second the RAM, the third is the CPU1 value and the last column is the CPU2 value
I want to display thoses informations like that :
FRAME : MO2PPC20 ========================================
RAM : 60
CPU 1 : 1.5
CPU 2 : 4
RAM : 39
CPU 1 : 0.3
CPU 2 :5
etc...
So, to do that, I use this little script :
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read FRAME RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV="$FRAME"
echo -e "FRAME : $FRAME \
========================================\n"
fi
echo -e "RAM :\t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done < <(sort "my_csv_file.csv")
My script works well in the case that I have one file in process.
So my first question is :
How to apply this script to all my csv in my directory ?
I think something like this :
for i in ` ls *.csv`
do
./my_script $i
done
And change the last line of my script for something simple such as :
#!/bin/bash
OLDIFS=$IFS
IFS=","
while read FRAME RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV="$FRAME"
echo -e "FRAME : $FRAME \
========================================\n"
fi
echo -e "RAM :\t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done
But it doesn't work...
And, the second question :
As soon as I am able to apply my script to all my csv, the informations from my csv will be display without distinction... I want to be able to display the file in process by my script like that :
File : my_csv_1.csv
FRAME : MO2PPC20 ========================================
RAM : 60
CPU 1 : 1.5
CPU 2 : 4
RAM : 39
CPU 1 : 0.3
CPU 2 :5
File : my_csv_2.csv
FRAME : XXXXXX
RAM : XXX
CPU 1 : XXX
CPU 2 : XXX
etc ...
Do you have any solutions for theses two questions ?
Thank you !