I have a .csv file and i use the below while loop to navigate through it
But i need to loop from the second line since the first line is the header
How will i do it?? please help
while IFS=, read Filename Path size readonly
do
echo "Filename -> ${Filename}"
echo "Path -> ${Path}"
echo "size -> ${size}"
echo "readonly -> ${readonly}"
done < filenames.csv
may be like this
no_of_line=`wc -l filenames.csv|cut -d' ' -f1`
tail -`expr $no_of_line - 1` filenames.csv | while .....
.
.
.
done
I am geting all the values including header when i do this
My csv file is like this
Filename,Path,size,readonly
file.sh,/File/test,20,Y
I need to retrieve the values from the second line excluding the header
How will i do that ??
May be we can think of writing the logic in awk/nawk...
awk '$0 != "Filename" { print $1,$2,$3,$4 }' filenames.csv
please modify the above logic or syntaxes as per your exact requirement.
i suggest samll modification in the above code
awk -F"," 'NR>1{print "Filename ->"$1"\nPath ->"$2"\nsize -> "$3"\nreadonly ->"$4}' filename
This awk command works perfect for me. But if i add this as a condition to my while loop its not working as expected
I need a condition which will restrict the header line from geting displayed
while looping:confused:
why you wanna run this in while loop??
awk will read each line of the file line by line so no need of loop.. and it will exclude the header
I need to execute other commands after looping through each line excluding the header line and assigning each column in a line to a variable
I believe if i loop using awk i wont be able to manipulate my loop
I dont know .correct me if i am wrong..
This can be used to achieve this
cat filenames.csv | while read fileline
do
filename1=`echo $fileline | cut -d "," -f1`
Path=`echo $fileline | cut -d "," -f2`
size=`echo $fileline | cut -d "," -f3`
readonly=`echo $fileline | cut -d "," -f4`
if [ $filename1 != "Filename" ]
then
..
..
fi
Thanks for all