Dec 5, 2008 #1 zhenning Technical User Sep 22, 2005 50 CA For example, if the input of the script is 3, I need to get the 3rd line from the bottom of the file as the output. How can I make it? Thanks a lot! Zhenning
For example, if the input of the script is 3, I need to get the 3rd line from the bottom of the file as the output. How can I make it? Thanks a lot! Zhenning
Dec 5, 2008 1 #2 feherke Programmer Aug 5, 2002 9,540 RO Hi A one-liner. ( The red 3 shows where to put the order number of the desired line. ) Code: perl -n -e '$n=[red]3[/red];' -e '$l[$.%$n]=$_;END{print$l[($.+1)%$n]}' /input/file Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi A one-liner. ( The red 3 shows where to put the order number of the desired line. ) Code: perl -n -e '$n=[red]3[/red];' -e '$l[$.%$n]=$_;END{print$l[($.+1)%$n]}' /input/file Feherke. http://rootshell.be/~feherke/
Dec 5, 2008 1 #3 KevinADC Technical User Jan 21, 2005 5,070 US Use the Tie::File module and you can access the lines of a file like an array. The third to last line would be index -3 in the tied array. ------------------------------------------ - Kevin, perl coder unexceptional! Upvote 0 Downvote
Use the Tie::File module and you can access the lines of a file like an array. The third to last line would be index -3 in the tied array. ------------------------------------------ - Kevin, perl coder unexceptional!
Dec 5, 2008 Thread starter #4 zhenning Technical User Sep 22, 2005 50 CA Thank you for all the applies! it worked for me! Upvote 0 Downvote