I'm searching backwards from the end of a file, it's probably easiest to explain by showing my code:enough=0numberOfLines=100fileName=/path/to.file# Tail the last $numberOfLines lines; if the line is within the time range we want them double how far we go backwhile [ $enough -eq 0 ]; do        # Get the date of the first line        dateOfFirstLine=`tail -$numberOfLines $fileName | sed -n 1p | grep -Po ^[0-9]{2}/[0-9]{2}-[0-9]{2}:[0-9]{2}:[0-9]{2}`        # See if it's still within the range we're interested in - if so then go back twice as far        if [[ $dateOfFirstLine > $startDate ]] ; then                numberOfLines=$((numberOfLines*2))        elif [[ $dateOfFirstLine == $startDate ]] ; then                numberOfLines=$((numberOfLines*2))        else                enough=1                lines=`tail -$numberOfLines $fileName`        fidone(I actually have an if in there that exits early if the number of lines we're tailing gets too high, but I've cut that out for simplicity)Obviously I then go on to do some work with $lines.My question is regarding this line:dateOfFirstLine=`tail -$numberOfLines $fileName | sed -n 1p | grep -Po ^[0-9]{2}/[0-9]{2}-[0-9]{2}:[0-9]{2}:[0-9]{2}`will that be quick and negligible in terms of CPU and I/O, because it only ever reads one line, or will it actually read all the lines but only the first one will move through the pipe?  I'm thinking tail still reads every line, right, in which case is there a better way of doing it?On a related note, how is wc -l so fast even for big files?  Is it not reading every character in the file and counting how many newline characters appear?  It just seems really quick if that's what it's doing - does the filesystem keep data like that handy or something?
Will tail -100 | sed -n 1p only read one line?
linux;bash;pipe;tail
Will tail -100 | sed -n 1p only read one line? No, sed will read 100 lines.If your goal is to read the 100th line from the end of the file, do one oftail -100 | head -1tail -100 | sed 1q