I would like know how I can read each line of a csv
file from the second line to the end of file in a bash script.
I know how to read a file in bash:
Or else (pure bash)...
{ for ((i=1;i--;));do read;done;while read line;do echo $line;done } < file.csv
Better written:
linesToSkip=1
{
for ((i=$linesToSkip;i--;)) ;do
read
done
while read line ;do
echo $line
done
} < file.csv
This work even if linesToSkip == 0 or linesToSkip > file.csv's number of lines
Edit:
Changed ()
for {}
as gniourf_gniourf enjoin me to consider: First syntax generate a sub-shell, whille {}
don't.
of course, for skipping only one line (as original question's title), the loop for (i=1;i--;));do read;done
could be simply replaced by read
:
{ read;while read line;do echo $line;done } < file.csv