Content-type: text/html Manpage of EXTRACT

EXTRACT

Section: User Commands (1)
Updated: local
Index  

NAME

extract, replace - extracts/replaces ranges of characters in files  

SYNOPSIS

extract [-n] range... file

replace [-n] range... file  

DESCRIPTION

Extract is used to copy out parts of a file and write it to the standard output. Replace performs the inverse operation: it overwrites parts of a file with replacement data read from the standard input.

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
or
           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.  

OPTIONS

The -n option, where n is an integer, specifies how the bytes in the file are counted: namely, the first byte is counted as byte number n. Thus -0 means to count from 0, while -1 means to count from 1 (the default).  

EXAMPLES

Suppose that file xxx has the following contents: abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz Here, each line has 26 printable characters followed by a newline. The command
      % extract 5-7 32:3 59-61 xxx
would print "efgEFGefg" on the standard output. The same result could be gotten by entering
      % extract 5-7/27 xxx

The following examples put "123" into characters 5-7, "456" into characters 32-34, and "789" into characters 59-61 of file xxx.
      % echo "123456789" | replace 5-7 32:3 59-61 xxx
      % echo "123456789" | replace 5-7/27 xxx  

AUTHOR

Will Deich  

BUGS

If an invalid range specification is found or there is not enough data available in the file to satisfy a range for extraction, extract and replace will exit with a message and the extractions or replacements only partly done.


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
EXAMPLES
AUTHOR
BUGS