4.88 right - Extract Substring from Right

Format 1: right($str$, length)

Format 2: rightw($str$, length)

Return the number of characters as defined in the parameter from the right side of the string in $str$. Use rightw function if the string contains multibyte characters.

Example

Example 1: Basic Example

Extract the last 3 characters from the end in the str column.

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

Example 2: Example of data containing multibyte characters

Use the function right if the data contains multibyte characters.

$ more dat2.csv
id,str
1,あいうえお
2,1234567あ8
3,1あ
4,ああ
$ mcal c='right($s{str},6)' a=rsl i=dat2.csv o=rsl2.csv
#END# kgcal a=rsl c=right($s{str},6) i=dat2.csv o=rsl2.csv
$ more rsl2.csv
id,str,rsl
1,あいうえお,えお
2,1234567あ8,67あ8
3,1あ,1あ
4,ああ,ああ