cat a range
Is it possible to cat ( or whatever else works ) a range of text. For example say I have a 500 line text file and I want to cat lines 200-250 , is this possible without custom scripting?
|
sure, check out 'man head'. this will show you the manual page for the 'head' command. head is used to show the first 10 lines of a file, by default. there is an option to specify the first X lines of a file.
|
To the best of my knowledge, "head" won't allow you to skip forward and start printing on line 200 as in the OP's example. "head" will work for printing the first lines of a file, "tail" for printing the last, but I don't think either will support printing the middle of a file. Maybe I should review the manpages on these two commands to find out for sure!
But I know you can use the "sed" command for this: Code:
sed -n -e'200,250p' /path/to/your/file |
sorry.. i misread the question. your right haertig. i thought he wanted to see the first 200 or 250 lines, in which case head would have worked. but thats not the case and i was wrong. thanks for clarifying.
|
Thanks guys. sed is exactly what i was looking for. Had I thought about it, I should have come up with it on my own Ayway, thanks.
|
If you don't know the specific line numbers for the section of the file you want, you can use sed with text strings also:
Code:
$ cat testfile |
Thanks a lot. It works but I dont understand the options. Man pages state
-e script -n silent -p umm i couldnt find that option I really appreciate the tip I'd just want to understand it. THANKS A LOT |
p = print
The "n" option suppresses printing, and then "p" says print when the stated conditions are matched. "p" is in the man page--look again. Better, however, is a good tutorial---like this: http://www.grymoire.com/Unix/Sed.html#uh-8 |
Of course, if you want something more basic than sed, both ed and ex use similar range tokens.
|
Another way - to show lines 20-25 of a text file:
head -n 25 foobar.txt | tail -n `expr 25 - 20 + 1` (or replace `expr ...` with the number of lines to show, in this example "6"). |
All times are GMT -5. The time now is 11:57 PM. |