3.69 mvdelim - Change Vector Delimiter

Change delimiter used to separate between string of characters in a vector. However, the delimiter will be removed if an empty string is specified as the delimiter.

Some examples are shown in Table 3.39 - 3.40. When comma is used as delimiter, a pair of double quotation marks is added to the vector (Table3.39). If a null character is specified as delimiter at v=, the delimiter between characters will be removed (Table 3.40).

Alphabet and chinese characters can be used as delimiter as shown in Table 3.40. Since the character type delimiter is read as character string as part of the vector by other commands such as mvsort, character type delimiter can be specified in delim=.

Table 3.39: input data
in.csv

no

items

1

b a a

2

a a b b

3

a b b a

4

a b c

: Caption text
Basic example : Replace space delimiter with minus character.

vf=items v=- i=in.csv

no

items

1

b-a-a

2

a-a-b-b

3

a-b-b-a

4

a-b-c

: Caption text
Use comma as a delimiter. vf=items v=, i=in.csv

no

items

1

"b,a,a"

2

"a,a,b,b"

3

"a,b,b,a"

4

"a,b,c"

Table 3.40: Remove delimiter between characters in a vector
vf=items v= i=in.csv

no

items

1

baa

2

aabb

3

abba

4

abc

: Caption text
Specify more than one character vf=items v=xx i=in.csv

no

items

1

bxxaxxa

2

axxaxxbxxb

3

axxbxxbxxa

4

axxbxxc

Format

mvdelim vf= v= [i=] [o=] [delim=] [-nfn] [-nfno] [-x] [--help] [--version]

vf=

Field name of vector to replace the delimiter. Multiple fields can be specified.

v=

Define new delimiter. If the parameter is not defined, the delimiter is treated as an empty character.

Example

Example 1: Basic Example

Replace the default space delimiter to _(underscore).

$ more dat1.csv
item1
b a c
c c
e a a
$ mvdelim vf=item1 v=_ i=dat1.csv o=rsl1.csv
#END# kgvdelim i=dat1.csv o=rsl1.csv v=_ vf=item1
$ more rsl1.csv
item1
b_a_c
c_c
e_a_a

Example 2: Comma

In CSV data with comma delimited characters, when the delimiter of vector is replaced as comma, the entire vector is enclosed in double quotes to differentiate from the delimiter of CSV.

$ mvdelim vf=item1 v=, i=dat1.csv o=rsl2.csv
#END# kgvdelim i=dat1.csv o=rsl2.csv v=, vf=item1
$ more rsl2.csv
item1
"b,a,c"
"c,c"
"e,a,a"

Related command