Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

cat in|while read s
do call "$s"

This needs to be modified so it runs only for arg+n lines. e.g.: 5

    cat in|while read s
for lines arg0 through arg0+n
    do call "$s" 
share|improve this question
up vote 0 down vote accepted

It'll be faster & cleaner to filter the input down to just the relevant lines before feeding it to the read loop:

cat in | sed "${start},${end}!d" | while read s; do
    call "$s"

Note: printing lines $1 through $1+n lines will actually print n+1 lines (e.g. printing lines 5 through 15 is actually 11 lines). If you want to print n lines starting at $1, use end=$((start+n-1)).

share|improve this answer
Would cat in | sed "${start},${end}!d" be faster than sed -n $1,+$np in? – user93200 Sep 28 '11 at 19:22
@user93200: I did some quick tests, and it seems to be the same speed. What would help is replacing the useless use of cat: sed "${start},${end}!d" <in | ... (unless, of course, cat in is just a placeholder for something less trivial). – Gordon Davisson Sep 29 '11 at 0:15
while read line; do
   if [ "$current" -gt "$lines" ] then exit 0; fi
   if [ "$current" -gt "$1" ] then call "$line"; fi
done < in
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.