sumoka
April 14, 2011, 1:31am
1
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.
hergp
April 14, 2011, 2:46am
2
Does it work, when you use:
export delm='\t'
...
sumoka
April 14, 2011, 5:30pm
3
No.. the same result... It doesn't seem to detect '\t' as a tab, what could be the reason ?
Scott
April 14, 2011, 5:52pm
4
printf "\t"
would likely work.
hergp
April 15, 2011, 4:54am
5
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
sumoka
April 15, 2011, 10:05am
6
Even in my case, the above code works.. my problem is, when I call it in the SQL using `echo $delm` it prints "\t" has anybody tried it calling in an sql ?
Scott
April 15, 2011, 12:37pm
7
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
binlib
April 15, 2011, 2:15pm
8
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.
sumoka
April 15, 2011, 2:37pm
9
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.
Scott
April 15, 2011, 3:14pm
10
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
1 Like