TPT scripting: Escaping characters in Atribute fields

Tools
Highlighted
N/A

TPT scripting: Escaping characters in Atribute fields

Hello guys, I'm new to TPT and I run into 

Here is a snippet of my TPT code 

 DEFINE OPERATOR OS_OPERATOR
DESCRIPTION 'OS CMD OPERATOR FOR TPT'
TYPE OS COMMAND
ATTRIBUTES
(
VARCHAR PrivateLogName = 'OS_CMD_log',
VARCHAR OsCmd = 'awk -F "[/,]" 'NR>1{printf("%s,%s,%s,%02d/%02d/%04d,%02d/%02d/%04d\n",$1,$2,$3,$4,$5,$6,$7,$8,$9)}' in_file > out_file',
VARCHAR IgnoreError = 'NO'
);

Basically, I'm trying to run this awk command that contains special characters that I assume don't work well with TPT (' " $)


awk -F "[/,]" 'NR>1{printf("%s,%s,%s,%02d/%02d/%04d,%02d/%02d/%04d\n",$1,$2,$3,$4,$5,$6,$7,$8,$9)}' in_file > out_file

How should I write my OsCmd  attribute in order to escape these special characters ?

A general answer of how to handle attribute values that contain special characters is most welcomed :)

1 REPLY
Junior Contributor

Re: TPT scripting: Escaping characters in Atribute fields

I can't test it right now, but I would assume you need to double the single quotes within the string:

VARCHAR OsCmd = 'awk -F "[/,]" ''NR>1{printf("%s,%s,%s,%02d/%02d/%04d,%02d/%02d/%04d\ n",$1,$2,$3,$4,$5,$6,$7,$8,$9)}'' in_file > out_file',