Computing.Net > Forums > Unix > Selecting specific lines from a fil

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Selecting specific lines from a fil

Reply to Message Icon

Name: pnbalaji
Date: September 25, 2008 at 09:53:56 Pacific
OS: AIX 5.3
CPU/Ram: 8GB
Product: IBM, 7026-H80
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 25, 2008 at 10:36:10 Pacific
Reply:

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

if ( NR > 200000)
print $0
} ' datafile


Then again, maybe you should let the shell do it:

#!/bin/ksh

cnt=0
while read line
do
((cnt+=1))
if [[ $cnt -gt 300000 ]]
then
break
fi

if [[ $cnt -gt 200000 ]]
then
echo "$line"
fi
done < data > newfile

Any way will take awhile


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Selecting specific lines from a fil

removing specific line from file www.computing.net/answers/unix/removing-specific-line-from-file/5042.html

extract a specific line from file www.computing.net/answers/unix/extract-a-specific-line-from-file/5381.html

getting a specific line from a file www.computing.net/answers/unix/getting-a-specific-line-from-a-file/7708.html