I have a large file, but I need a part of it, the lines between line m
(1000) and line n
(2000).
How can I get it? (and put it into a new smaller file, or print on screen)
I have a large file, but I need a part of it, the lines between line m
(1000) and line n
(2000).
How can I get it? (and put it into a new smaller file, or print on screen)
You can do it easily with sed
:
sed -n 'm,n p' bigfile > smaller_file
assuming m and n are numbers
Here, you're using:
sed
's addresses, specifying ranges by line numbers:Sed commands can be given with no addresses, in which case the command will be executed for all input lines; with one address, in which case the command will only be executed for input lines which match that address; or with two addresses, in which case the command will be executed for all input lines which match the inclusive range of lines starting from the first address and continuing to the second address. Three things to note about address ranges: the syntax is addr1,addr2 (i.e., the addresses are separated by a comma); the line which addr1 matched will always be accepted, even if addr2 selects an earlier line; and if addr2 is a regexp, it will not be tested against the line that addr1 matched.
If file is huge it is better to exit the file browsing as soon as end
line is reached. You can use this awk:
awk -v m=10 -v n=15 'NR>n{exit} NR>=m' file > file_chunk