4.65 mid - Extract Substring

Format 1: mid($str$, starting position, length)

Format 2: midw($str$, starting position, length)

Extract the character string $str$ from the specified starting position for a specified length. Note that the starting position starts from 0. Use leftw function if the string contains multibyte characters.

Example

Example 1: Basic Example

Extract the first 3 characters from the beginning in the str column.

$ more dat1.csv
id,str
1,abcdefg
2,12345678
3,
4,12
$ mcal c='mid($s{str},2,3)' a=rsl i=dat1.csv o=rsl1.csv
#END# kgcal a=rsl c=mid($s{str},2,3) i=dat1.csv o=rsl1.csv
$ more rsl1.csv
id,str,rsl
1,abcdefg,cde
2,12345678,345
3,,
4,12,