I have one question about my script.
I have this kind of csv file to process with my script :
RXK7;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK6;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK4;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK1;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK2;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK5;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
RXK3;MIAO24;Running;Linux;24;16;32;DefaultPool;shared
I want to keep only the 1,2,5,6 and 7 columns. To do that, I use this command :
cat test.csv | awk -F',|;' '{print $1","$2","$5","$6","$7}'
And the result is :
RXK7,MIAO24,24,16,32
RXK6,MIAO24,24,16,32
RXK4,MIAO24,24,16,32
RXK1,MIAO24,24,16,32
RXK2,MIAO24,24,16,32
RXK5,MIAO24,24,16,32
RXK3,MIAO24,24,16,32
With my script :
#!/bin/bash
OLDIFS=$IFS
IFS=','
for arg
do
echo "File :" $arg | cut -d'.' -f1
echo "======================================================="
echo ""
while read FRAME LPARS RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV=$FRAME
echo "FRAME : $FRAME"
echo -e "-----------------\n"
fi
echo -e "LPARS :\t$LPARS\n\
RAM : \t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done < "$arg"
done
I can display theses informations of my differents csv like that :
File : test2
=======================================================
LPARS :
RAM :
CPU 1 :
CPU 2 :
FRAME : RXK7
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK6
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK4
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK1
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK2
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK5
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
FRAME : RXK3
-----------------
LPARS : MIAO24
RAM : 24
CPU 1 : 16
CPU 2 : 32
But this is possible only if I create a temporary file beforehand :
cat test.csv | awk -F',|;' '{print $1","$2","$5","$6","$7}' > test2.csv
I want to know if it's possible to do this without the need to create a temporary file ? I think something like :
for arg
do
echo "File :" $arg | cut -d'.' -f1
echo "======================================================="
echo ""
cat $arg | awk -F',|;' '{print $1","$2","$5","$6","$7}' | while read FRAME LPARS RAM CPU1 CPU2
do
if [[ $FRAME != $PREV ]]
then
PREV=$FRAME
echo "FRAME : $FRAME"
echo -e "-----------------\n"
fi
echo -e "LPARS :\t$LPARS\n\
RAM : \t$RAM\n\
CPU 1 :\t$CPU1\n\
CPU 2 :\t$CPU2\n"
echo ""
done < "$arg"
done
Or maybe it's possible to do this only with awk ?
Thank you for your help !
\tand\n. Or I would use Perl :) . Anyway, if you remove the< "$arg"afterdone, I think the code you have might actually work. Edit and in the awk code, change","to" ".awk -F',|;' '{ print "\nFRAME:",$1; print "==================="; print "\nLPARS:",$2; print "\nRAM:",$5; print "\nCPU1:",$6; print "\nCPU:",$7 }' input.txt