Unable to export delimiter as variable to SQL

Hi,

I'm using a shell wrapper to trigger a teradata sql fastexport script as follows:

#!/bin/ksh

export delm=`echo "\t"`

fexp <<!
SELECT
COALESCE(TRIM(CAST(col1 AS VARCHAR(10))),'')
||'$delm'|| COALESCE(CAST(col2 AS VARCHAR(10)),'')
||'$delm'|| COALESCE(TRIM(col3),'')
FROM TABLE;

.END EXPORT;
.LOGOFF;

I also tried 'echo $delm' & `echo $delm` in all the cases it gives me "\t" in between the column values instead of tab " ".

so, I tried with

export delm=`echo "     "`

thats working fine.

I don't want to use that. has anybody a solution ? am I doing anything wrong ?

Suyog.

Does it work, when you use:

export delm='\t'
...

No.. the same result... It doesn't seem to detect '\t' as a tab, what could be the reason ?

printf "\t" would likely work.

Hmm, both the single and double quote version work here on ksh88 on Solaris 10.

$ delim="\t"
$ print x${delim}x
x       x
$ delim='\t'
$ print x${delim}x
x       x

I double checked on a Linux system with pd-ksh, it works there too.

---------- Post updated at 10:54 ---------- Previous update was at 10:46 ----------

Just saw, that this approach does not work with a here document. This version works also with a here document on my machine:

#!/bin/ksh
delm=$(printf "\t")
cat <<!
x${delm}x
!

Output:

x       x

Even in my case, the above code works.. my problem is, when I call it in the SQL using `echo $delm` it prints "\t" :stuck_out_tongue: has anybody tried it calling in an sql ?

Hi.

Not sure why you are still using echo, when it should work fine using printf!:

#!/bin/ksh

export delm=`printf "\t"`

cat <<!
SELECT
COALESCE(TRIM(CAST(col1 AS VARCHAR(10))),'')
||'$delm'|| COALESCE(CAST(col2 AS VARCHAR(10)),'')
||'$delm'|| COALESCE(TRIM(col3),'')
FROM TABLE;

.END EXPORT;
.LOGOFF;
!

Output:

SELECT
COALESCE(TRIM(CAST(col1 AS VARCHAR(10))),'')
||'	'|| COALESCE(CAST(col2 AS VARCHAR(10)),'')
||'	'|| COALESCE(TRIM(col3),'')
FROM TABLE;

.END EXPORT;
.LOGOFF;

If you're still getting \t, then try using printf "\011"

1 Like

With most shells, echo is a built-in. In bash, you would need the -e option to enable the backslash interpretation. With ksh on Solaris, echo behaves differently depending on where /usr/ucb appears in your PATH.

U r right.. my bad.. shouldn't have echo'ed it!

That worked, thanks!

btw.. how do you get the binary code? is there any conversion or standard list available ? please share.

Suyog.

Hi.

It just comes from the ASCII table, \011 being Octal for 9 decimal - a horizontal tab

ASCII - Wikipedia, the free encyclopedia

You can also use:

$ man ascii

to get ASCII table on most of the systems, when Internet connection might be a problem :wink:

1 Like

Thanks. I had no idea :smiley: