Advertisement

02.23.2007 at 11:23AM PST, ID: 22409840
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Display TAB in Shell Script

Tags: shell, tab, script
Hello All,
I need help in displaying the tab character in UNIX.  I am writing a script which will load the tab delimited text file into a Teradata table. I tried to use the below but it didn’t work

TAB= “\t”
echo "Hello${TAB}World"
TAB1='\t'
echo "Hello${TAB1}WORLD"

Both the echo statements displayed the tab in between the string ‘Hello      World’. But in the script after connecting to the database the $TAB is displayed as \t. Can anyone help me out on this issue to populate the tab character? Below is the line of code I use in my script to populate the TAB character. If I use a tab like “      “ the script works fine.

SET RECORD VARTEXT "$TAB";

$ echo $SHELL
/usr/bin/sh
Start your free trial to view this solution
Question Stats
Zone: OS
Question Asked By: cutie_smily
Solution Provided By: siliconbrit
Participating Experts: 5
Solution Grade: A
Views: 169
Translate:
Loading Advertisement...
02.23.2007 at 12:08PM PST, ID: 18598856

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2007 at 12:26PM PST, ID: 18598975

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2007 at 02:23PM PST, ID: 18599762

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2007 at 02:52PM PST, ID: 18599954

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2007 at 02:53PM PST, ID: 18599960

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.23.2007 at 03:52PM PST, ID: 18600221

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.26.2007 at 11:19PM PST, ID: 18615233

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.28.2007 at 07:25AM PST, ID: 18625715

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2007 at 09:17AM PST, ID: 18642540

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2007 at 10:41AM PST, ID: 18643156

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2007 at 11:28AM PST, ID: 18643501

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.23.2007 at 12:08PM PST, ID: 18598856

Rank: Master

Hi cutie,

Where exactly is the tab displaying as '\t'?  Do you know what command or commands are involved?

 
02.23.2007 at 12:26PM PST, ID: 18598975

Rank: Wizard

You may need to to

/bin/echo "Hello${TAB}World"

or

echo -t "Hello${TAB}World"
 
02.23.2007 at 02:23PM PST, ID: 18599762

Rank: Guru

if the \t in your post represents a real tab in your script, then
echo "Hello${TAB}World" should print a real tab
 
02.23.2007 at 02:52PM PST, ID: 18599954
Sorry for not being clear. The echo works fine before connecting to the database. Once I connect to the database it is displayed as /t.

Below is the sample script
USERID=$1
DATABASE=$2
TABLE=$3
DATAFILE=$4
TAB="\t"

LOGON=`cat ${BIN_DIR/USERID}_logon`
fastload << EOF
${LOGON}
DROP TABLE ${DATABASE}.${TABLE}_Err1;
DROP TABLE ${DATABASE}.${TABLE}_Err2;
ERRLIMIT 50;

BEGIN LOADING
${DATABASE}.${TABLE}
   ERRORFILES ${DATABASE}.${TABLE}_Err1,
              ${DATABASE}.${TABLE}_Err2
   CHECKPOINT 100000;

SET RECORD VARTEXT "${TAB}";

DEFINE
     Col1       (VARCHAR(5))
     ,col2     (VARCHAR(2))
     ,col3      (VARCHAR(12))

I get an error on the line SET RECORD VARTEXT "${TAB}"; becuase in the log the value of $TAB shows as \t.
Below is the error
0006 SET RECORD VARTEXT "\t";

**** 17:48:25 Incorrect syntax for delimiter character specification
**** 17:48:25 Command not processed

If I hardcode the tab like SET RECORD VARTEXT "    "; then it works but I want to parameterize so that in future I can change to any delimiter I want to.
Thanks
 
02.23.2007 at 02:53PM PST, ID: 18599960

Rank: Master

Does your Unix have the 'printf' command? If so, then something like this will do the trick:

printf "%s\t%s\n" Hello World
 
02.23.2007 at 03:52PM PST, ID: 18600221

Rank: Master


Hi cutie,

I found one reference to this issue, and it seems that "\t" works.  But it may require certain conditions that aren't obvious.

  http://www.webservertalk.com/archive286-2005-11-1306144.html
  http://archives.devshed.com/forums/databases-139/loading-tab-delimited-text-file-using-fastload-teradata-1609484.html
 

The links are to the same thread.


Kent
Assisted Solution
 
02.26.2007 at 11:19PM PST, ID: 18615233

Rank: Guru

can you hardcode the tab like
TAB="    "
Assisted Solution
 
02.28.2007 at 07:25AM PST, ID: 18625715

Rank: Master


The problem is that you are passing the value of your delimiter to an input (<<) statement, as part of your database statement. The string passed via (<<) is being sent literally, as you have typed it.

So, in your example, the value of "${TAB}" is expanded literally, so that you are actually passing "\t" as the delimiter, and not a tab character as you expect.

You say you would like to do this in case the delimiter changes in a later iteration, which is commendable when you are writing a generic script, but since your script uses 'drop table', which is an aggressive and job-specific task, I wouldn't bother trying to genericise the script, just type the tab in place.

If you really want a generic script, you should at least:

1) Move the database instructions to an external file, passed to the script either as stdin, or as a named file parameter, or as an editable constant like you have with TAB

2) Instead of varying the value you pass to SET RECORD VARTEXT, you should always use the same delimiter, and instead pass the input file through a sed command to bring it into the format required by the script, by replacing the delimiter for that file with the delimiter enforced by the script.

However, if you insist on doing it this way, pretending to have a generic script, you can achieve this in a number of ways:

A) By breaking down the "<<" statement into three steps:

#step 1
fastload << EOT1
${LOGON}
DROP TABLE ${DATABASE}.${TABLE}_Err1;
DROP TABLE ${DATABASE}.${TABLE}_Err2;
ERRLIMIT 50;

BEGIN LOADING
${DATABASE}.${TABLE}
   ERRORFILES ${DATABASE}.${TABLE}_Err1,
              ${DATABASE}.${TABLE}_Err2
   CHECKPOINT 100000;

SET RECORD VARTEXT
EOT1

# step 2
fastload << $TAB

# step 3
fastload << EOT2
;
DEFINE
     Col1       (VARCHAR(5))
     ,col2     (VARCHAR(2))
     ,col3      (VARCHAR(12))

EOT2


B) By removing the quotes.  Note that the syntax ${..} implies a quote itself, so you are essentially passing ""\t"".  Anyway, just try replacing "${TAB}" with $TAB and see if that works.  If it doesn't, you need to split the << input so that the TAB is passed outside of any other string.
Accepted Solution
 
03.02.2007 at 09:17AM PST, ID: 18642540
Apologize for getting back late.

siliconbrit, Thanks for the detail explanation.
Kdo, Thanks for the search
Ozo, Thanks the TAB="     " worked for me.
Can you please let me know which is the best way to pass a tab in the command line parameter of a script. Ex: in the script TAB=$4 then how can I pass tab to the 4th parameter. Except: "   " is there any better way of doing?

Thanks guys for all the help. I will close the question as soon as i get the answer.
 
03.02.2007 at 10:41AM PST, ID: 18643156

Rank: Master


When the shell invokes your command, it will expand any tab character as whitespace, unless that whitespace is quoted.  Therefore, there is no other way of passing your tab as a command-line parameter unless it is quoted.

Even quoted tabs may not pass correctly depending on your prevailing shell and version of UNIX, although in this instance, you should be safe since you are using the core bourne shell.

However, please let me say again that you are approaching this the wrong way around.  You are going to the trouble of creating a 'generic' script, by concerning yourself with the tab character, while the script includes code which is job-specific.

If you genuinely have input files that might be delimited by one of many characters, why dont you make the first job in your script to format the input file into a standard delimited file and *then* pass it to your database job.  So, if the file is delimited by spaces, or commas, replace these with tabs into a temporary file, then work with that file instead.

Furthermore, there is probably a limited number of possible delimiters that could be used depending on your data, and there is probably a known architecture to the input file, so for example it may be possible to work out that the delimiter character is always the sixth character in the file.
Assisted Solution
 
03.02.2007 at 11:28AM PST, ID: 18643501
Thanks siliconbrit for the clear explanation. I made this script to the job specific.

Thanks to all of you for the help.
 
 
20080236-EE-VQP-29