parse lines

I have file which is having 500 lines. I want to get the first 100 lines then sleep, then again next 100 lines sleep so now till the end of the file.

Can someone tell me in perl and bash.

also i want to do it in threads.

Thanks..

 
awk '{if(NR%100){system("sleep 2")}}1' inputfile.txt

Above code is getting sleep each line, i want it to sleep after 100 lines of output, and then sleep and then output next 100 lines etc.

With a slight modification of the code of itkamaraj:

awk '{if(!(NR%100)){system("sleep 2")}}1' inputfile.txt
2 Likes

Thanks it works. Can someone tell me how to do it in perl

---------- Post updated at 07:21 AM ---------- Previous update was at 07:09 AM ----------

Franklin52 can u tell me what NR% means in awk statement?

I found how do it in perl

NR is Special Variable in AWK which means Number of Line the process is on. Hence

NR%100

will give you the remainder of NR/100. So here, if NR is 101, the NR%100 will give 1 which will invalidate !(NR%100)

Ok thanks, got it