3.72 mvnullto - Replace NULL in vector elements

Replace NULL elements in the vector with an ad hoc value. If NULL element exist in the vector, there will be consecutive delimiters of the elements. All the vectors described below contain NULL element. However, for ease of reading, `\n' is added at the end of each vector. Reading from the top row, the 3rd element, 1st element, and 4th element are NULL.

a b  c\n
 a b\n
a b c \n

Format

mvnullto vf= [v=|-p] [O=] [-A] [delim=] i= [o=] [delim=] [-nfn] [-nfno] [-x] [--help] [--version]

vf=

Specify the field name (i=on file) to replace NULL.

 

Multiple items can be specified.

v=

Specify the replacement string.

-p

Replace NULL with the previous element. It can not be specified with v=.

O=

Replace all non-NULL elements with the string specified here.

 

Non-NULL value will not be replaced unless specified.

-A

Instead of replacing the specified item, this option adds output as a new field.

 

When -A open is specified, the new field name must be specified after :(colon).

 

Example: f=quantity:substitution field name

Examples

Example1: Replace null characters to the character string ’null’

$ more dat1.csv
items
b a  c
 c c
e a   b 
$ mvnullto vf=items v=null i=dat1.csv o=rsl1.csv
#END# kgvnullto i=dat1.csv o=rsl1.csv v=null vf=items
$ more rsl1.csv
items
b a null c
null c c
e a null null b null

Example 2: Use .(dot) as delimiting character

$ more dat2.csv
items
b.a..c
.c.c
e.a...b.
$ mvnullto vf=items v=null delim=. i=dat2.csv o=rsl2.csv
#END# kgvnullto delim=. i=dat2.csv o=rsl2.csv v=null vf=items
$ more rsl2.csv
items
b.a.null.c
null.c.c
e.a.null.null.b.null

Example 3: Replace null with the previous value

$ mvnullto vf=items -p i=dat1.csv o=rsl3.csv
#END# kgvnullto -p i=dat1.csv o=rsl3.csv vf=items
$ more rsl3.csv
items
b a a c
 c c
e a a a b b

Example 4: Replace all values except null by specifying O=

$ mvnullto vf=items v=null O=X i=dat1.csv o=rsl4.csv
#END# kgvnullto O=X i=dat1.csv o=rsl4.csv v=null vf=items
$ more rsl4.csv
items
X X null X
null X X
X X null null X null

Related command

mvdelnull : Delete a NULL element.