replace [-n] range... file
Replacements can only be done on files on which fseek(3) will succeed. Extractions can be done from any stream; the filename `-' means the standard input. If the input is not coming from a plain file, the ranges must be in increasing order, since in that case extract will read past the undesired data instead of performing a seek.
The parts of the file that are extracted or overwritten are specified by the ranges, which are of the form
first-last or first-last/step
first:length or first:length/step
Here, first specifies the first character position of the range that is to be extracted or overwritten. In the first form, last specifies the last character position in the range; in the second form, the length gives the number of characters in the range. Characters in the file are counted starting from 1, but this can be changed with the -n option. The positions are all decimal integers, and in addition, last can be given as $, which stands for the last position in the file. (Remember that the $-sign will often have to be escaped in shell commands.)
The optional step parameter indicates that the range should be stepped through the file: first...last are extracted or overwritten; then first+step...last+step; then first+(2*step)...last+(2*step); and so on, stopping only when last exceeds the filesize.
The following examples put "123" into characters 5-7,
"456" into characters 32-34, and "789" into characters 59-61 of file
% echo "123456789" | replace 5-7 32:3 59-61 xxx
% echo "123456789" | replace 5-7/27 xxx