Quick Help...Shell script...
Posted in 2000
Topics: General Discussion
Hi All, How can i get nth line (for example say 100th line) from a text file directly? I don't want to scan whole file for that using a loop. Like TOP and TAIL command, is there anything to read a range of lines in-between? Thanks in advance Prasad _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. Share information about yourself, create your own public profile at http://profiles.msn.com.
You could use awk awk '{if (NR==100) {print $0}}' filename Of course, this does read the whole file, but only prints the one line you are looking for. Sean Prasad Mahale wrote: > Hi All, > How can i get nth line (for example say 100th line) from a text file > directly? > I don't want to scan whole file for that using a loop. > Like TOP and TAIL command, is there anything to read a range of lines > in-between? > > Thanks in advance > Prasad > > _________________________________________________________________________ > Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. > > Share information about yourself, create your own public profile at > http://profiles.msn.com.
Prasad Mahale wrote: > > How can i get nth line (for example say 100th line) from a text file > directly? Some versions of "tail" allow you to specify the distance from the front of the file. On my system, the construct is to use "tail +number" instead of "tail -number". Check tail's man page on your system. On my system (Solaris 7), the solution would be: tail +100 file | head -1 HTH, Walt. -- Walt Hultgren Manager, Information Technology Yerkes Research Center of Emory University Mailto:walt@rmy.emory.edu -- 404-727-0648