replace - replace a row
SYNOPSIS
replace [-fc] [-m[bhirs]] [+a|-a] [-b] tableorlist from to [xfrom xto] < newrow
DESCRIPTION
replace
inserts a single input row from
newrow
in
tableorlist
at the
from
location specified.
When
-m
is specified,
replace
also updates the associated index file at the
xfrom
location.
It will not insert a row which is longer than the
difference between
to
and
from.
replace
pads the last column of rows
are smaller than the size of the original record (to - from).
OPTIONS
- -fc
- c
(not TAB) is the input column separation character.
- -Dn
- turn on debugging at level n, or 1 if n
is not specified.
- -m [bhirs]
- See
index
for the fast access method options.
- +a
- always append the row to the end of the file,
even if it fits in the original row.
- -a
- if the replacement row is too big to fit
in the original position do
not
append it to the end of the file.
This option may be specified
in cases where it is critical to maintain
a particular row order.
- -b
- write a blank row at the
original position in the file when the record replacing it is
larger and must be appended to the end of the file.
This eliminates the need to use
blank
on the original row
in a separate process.
EXAMPLES
$ cat inventory
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
First, extract the row to be updated with the
seek
program and save the offset in the
LOCATION
shell variable.
This example uses the
record
method:
$ LOCATION=`echo 5 | seek -mr -o rowupdate inventory Item`
$ echo $LOCATION
207 245 54 62
$ cat rowupdate
Item Amount Cost Value Description
---- ------ ---- ----- --------------
5 99 24 2376 cleaning cloth
Now let's change
Amount
in
rowupdate
to 44 and update the
Value
column:
$ compute "Amount = 44;
Value = Cost * Amount" < rowupdate
Item Amount Cost Value Description
---- ------ ---- ----- --------------
5 44 24 1056 cleaning cloth
Let's repeat that command and replace the old row
as well:
$ compute "Amount = 44;
Value = Cost * Amount" < rowupdate |\\
replace -mr inventory $LOCATION
$ cat inventory
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 44 24 1056 cleaning cloth
6 89 147 13083 bunsen burners
AKA
SEE ALSO