0

a.sh

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

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

    cat in|while read s
n=10
for lines arg0 through arg0+n
    do call "$s" 
    done
0

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

n=10
start=$1
end=$((start+n))
cat in | sed "${start},${end}!d" | while read s; do
    call "$s"
done

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)).

| 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
0
lines=10
current=0
while read line; do
   current=current+1
   if [ "$current" -gt "$lines" ] then exit 0; fi
   if [ "$current" -gt "$1" ] then call "$line"; fi
done < in
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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