155 lines
3.6 KiB
Groff
155 lines
3.6 KiB
Groff
.TH replace "" "" "/rdb Command"
|
|
.PC "Insert a record into a file at specified location"
|
|
\fBreplace [\-a] [\-m[bhirs] \fItableorlist from to \fB[\fIxfrom xto\fB] < \fIintableorlist\fR
|
|
.PP
|
|
.II row^replace
|
|
The command
|
|
.B replace
|
|
replaces the row at offsets
|
|
.I from
|
|
through
|
|
.I to
|
|
in
|
|
.I tableorlist
|
|
with the contents of
|
|
.IR intableorlist .
|
|
.B replace
|
|
will not insert a record larger than
|
|
.I to
|
|
minus
|
|
.IR from .
|
|
It adds spaces to the
|
|
.I last
|
|
column of records within
|
|
.I tableorlist
|
|
that are smaller than the input record.
|
|
.PP
|
|
.I xfrom
|
|
and
|
|
.I xto
|
|
give the beginning and end of the offsets of the index entry within
|
|
.IR tableorlist 's
|
|
associated fast-access table, should there be one.
|
|
.PP
|
|
To obtain painlessly the offsets of the record and its index entry, use
|
|
the command
|
|
.BR seek .
|
|
This is demonstrated in the following example.
|
|
.PP
|
|
The command
|
|
.B update
|
|
remembers the location and size of the record it takes out of a file
|
|
and passes it to
|
|
.B replace
|
|
so that only a correctly sized file goes back into that file.
|
|
.SH Options
|
|
.B replace
|
|
recognizes the following options:
|
|
.IP \fB\-a\fR
|
|
Do not append the record in
|
|
.I intableorlist
|
|
to the end of
|
|
.IR tableorlist .
|
|
The default to append if the record is too big
|
|
to fit back into the location from which it was taken.
|
|
This option allows you to prevent appending.
|
|
If you want a binary file to stay
|
|
sorted, you will either have to resort it or not allow appending.
|
|
.IP \fB\-m[bhirs]\fR
|
|
Fast access methods.
|
|
See the manual page for
|
|
.B index
|
|
for a description of what each of these options means.
|
|
.SH Example
|
|
If table
|
|
.B recordtable
|
|
contains one record, you use can insert that record into table
|
|
.B bigfile
|
|
with the following command:
|
|
.DM
|
|
replace bigfile 1421 1487 0 8 < recordtable
|
|
.DE
|
|
.PP
|
|
Note that the contents of
|
|
.B recordtable
|
|
replace rows 1421 through 1487 within
|
|
.BR bigfile .
|
|
.PP
|
|
For the second example, consider again table
|
|
.BR inventory ,
|
|
as follows:
|
|
.DM
|
|
Item Amount Cost Value Description
|
|
---- ------ ---- ----- --------------
|
|
1 3 50 150 rubber gloves
|
|
2 100 5 500 test tubes
|
|
3 5 80 400 clamps
|
|
4 23 19 437 plates
|
|
5 99 24 2376 cleaning cloth
|
|
6 89 147 13083 bunsen burners
|
|
7 5 175 875 scales
|
|
.DE
|
|
.PP
|
|
First, let's use the command
|
|
.B seek
|
|
to extract a record, and save its offset in the shell variable
|
|
.BR LOCATION :
|
|
.DM
|
|
LOCATION=`echo 5 | seek -mr -o tmpfile inventory Item`
|
|
.DE
|
|
.PP
|
|
.B $LOCATION
|
|
is initialized to the following
|
|
.DM
|
|
207 245 54 62
|
|
.DE
|
|
.PP
|
|
and
|
|
.B tmpfile
|
|
contains the following:
|
|
.DM
|
|
Item Amount Cost Value Description
|
|
---- ------ ---- ----- --------------
|
|
5 99 24 2376 cleaning cloth
|
|
.DE
|
|
.PP
|
|
Here we use the record fast-access method.
|
|
.PP
|
|
Now let's
|
|
change 99 to 199 within
|
|
.BR tmpfile ,
|
|
so we can see a change:
|
|
.DM
|
|
Item Amount Cost Value Description
|
|
---- ------ ---- ----- --------------
|
|
5 199 24 2376 cleaning cloth
|
|
.DE
|
|
.PP
|
|
Now we can replace the edited record in
|
|
.BR inventory :
|
|
.DM
|
|
replace -mr inventory $LOCATION < tmpfile
|
|
.DE
|
|
.PP
|
|
.B inventory
|
|
now appears as follows:
|
|
.DM
|
|
Item Amount Cost Value Description
|
|
---- ------ ---- ----- --------------
|
|
1 3 50 150 rubber gloves
|
|
2 100 5 500 test tubes
|
|
3 5 80 400 clamps
|
|
4 23 19 437 plates
|
|
5 199 24 2376 cleaning cloth
|
|
6 89 147 13083 bunsen burners
|
|
7 5 175 875 scales
|
|
.DE
|
|
.PP
|
|
You can see that row 5 has been updated, because it now has
|
|
199 in it.
|
|
.SH "See Also"
|
|
.B
|
|
seek,
|
|
update
|
|
.R
|