| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
On 2015-03-30 08:33, [email protected] [sed-users] wrote:
> I have a file which can be divided into n equal parts and i need
> to print the mth part. where m,n are integers and m =< n.
>
> For Ex: if a file contains 100 lines and is divided into 10 (n)
> parts and if i need to print the 7(m) part, the output is from 61
> to 70 lines.
How are the parts delimited? If they're by lines and you know the
dividing factor, do you also need to know the total number of lines
in the file to determine the part-size?
If they're lines and you know the block-size (10 lines, you mention),
you can use
i=7
bs=10
... | sed -n "$((${i}*${bs})),$((${i}*${bs}+${bs}-1))p"
which has Bash calculate the range to print and then sed prints those
particular lines.
-tim