3.52 msetstr - Add String Column

Add specified string as new field(s) in all rows. More than one fields can be added.

Format

msetstr v= a= [i=] [o=] [-nfn] [-nfno] [-x] [--help] [--version]

Parameters

v=

List of character strings to add.

 

NULL value is added if the value is not specified.

a=

Add field name.

 

The number of string and field name of specified at v= must be the same number. v=.

Examples

Example 1: Basic Example

Calculate the date by setting a reference date (defined as January 01, 2007) and add the string “20070101” in all lines and save the output as a new column named “ReferenceDate”.

$ more dat1.csv
customer,date
A,20081202
A,20081204
B,20081203
$ msetstr v=20070101 a=ReferenceDate i=dat1.csv o=rsl1.csv
#END# kgsetstr a=ReferenceDate i=dat1.csv o=rsl1.csv v=20070101
$ more rsl1.csv
customer,date,ReferenceDate
A,20081202,20070101
A,20081204,20070101
B,20081203,20070101

Example 2: Add multiple fields

$ msetstr v=20070101,20070201 a=RefDate1,RefDate2 i=dat1.csv o=rsl2.csv
#END# kgsetstr a=RefDate1,RefDate2 i=dat1.csv o=rsl2.csv v=20070101,20070201
$ more rsl2.csv
customer,date,RefDate1,RefDate2
A,20081202,20070101,20070201
A,20081204,20070101,20070201
B,20081203,20070101,20070201

Example 3: Add column with null values

$ msetstr v= a=NewColumn i=dat1.csv o=rsl3.csv
#END# kgsetstr a=NewColumn i=dat1.csv o=rsl3.csv v=
$ more rsl3.csv
customer,date,NewColumn
A,20081202,
A,20081204,
B,20081203,

Related Command

mcal : Use the if function to add a fixed string according to differently conditions for each row.