how to read file from line x to the end of a file in bash
tail -n +2 file.csv
From the man page:
-n, --lines=N
output the last N lines, instead of the last 10
...
If the first character of N (the number of bytes or lines) is a '+',
print beginning with the Nth item from the start of each file, other-
wise, print the last N items in the file.
In English this means that:
tail -n 100
prints the last 100 lines
tail -n +100
prints all lines starting from line 100
Simple solution with sed
:
sed -n '2,$p' <thefile
where 2
is the number of line you wish to read from.
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
There are many solutions to this. One of my favorite is:
(head -2 > /dev/null; whatever_you_want_to_do) < file.txt
You can also use tail
to skip the lines you want:
tail -n +2 file.txt | whatever_you_want_to_do