Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have a file containing 556,247 lines in it. I would like to extract the lines from 200,000 to 300,000. How do I acheive this using a single sed or awk command? Can some one help?
Thanks,
Balaji.

This sed command prints the first 13 lines:
sed -n '1,13p' datafile
I've never tried to edit a file this large before:
sed -n '200000,300000p' datafile > newdatafile
It'll be interested see if it works.
Of course, you could do it with awk:
awk ' { if (NR > 300000 )
exitif ( NR > 200000)
print $0
} ' datafile
Then again, maybe you should let the shell do it:
#!/bin/kshcnt=0
while read line
do
((cnt+=1))
if [[ $cnt -gt 300000 ]]
then
break
fiif [[ $cnt -gt 200000 ]]
then
echo "$line"
fi
done < data > newfileAny way will take awhile

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |