a simple question
Hi..Is there a bash shell command which exactly selects and returns the given numbered line in a file (ex. 3rd line)?Thanks..
|
Do you mean something like this?
Code:
sed -n '3p' file.txt |
basak and homey,
Here is another way: head -3 file.txt | tail -1 This captures the first 3 lines of file.txt then displays only the last of these lines. This approach can easily be modified to get a range of lines, for example: head -2 file.txt | tail -3 gives the third line and the lines directly before and after it (lines 2-4). 'head' and 'tail' are two simple utilities that are very useful when you do not need to do something more complicated with sed, awk, perl, etc. You might want to check out the man pages for both. If you find another (and especially if you find a better) way, please post it here. |
Sed makes my brain bleed. I wrote a log stripper which implimented sed heavily... gahhhhh. Worked amazing when I finally figured out how to do all that I wanted to do though... very versatile program.
|
All times are GMT -5. The time now is 05:53 AM. |