Problem with tabs expansion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with tabs expansion
# 1  
Old 09-28-2010
Problem with tabs expansion

I have to create some fixed width files using UNIX. The data source is an Oracle SQL query. If I use straight SQL and spool to a file everything comes out as expected.

Example Desired result (. indicate blank space):
V278814831..................................1743049591.10N
V154369133..................................1743049841.10N

If I perform the file creation using UNIX:
Code:
sqlplus -s test/testpwd@testdb @spool_script2_test.sql >jss.dat

The file is created but every 8 spaces are automatically converted to tabs.
Example result (. indicate blank space, > indicate a tab equal to 8 spaces):
V278814831> > > > ..1743049591.10N
V154369133> > > > ..1743049841.10N

How can I prevent this automatic conversion? I have found way to revert the file to the desired state for example:
Code:
expand -8 jss.dat >jss_new.dat

but I don't want to do this. I want to stop the tab conversion in the first place. How can I do this? Smilie

I have talked with several co-workers and no one knows the answer, only workarounds.

Please help...

Last edited by vbe; 09-28-2010 at 01:08 PM.. Reason: code tags please
# 2  
Old 09-28-2010
To get spaces in terminal output:
Code:
set tab off

This User Gave Thanks to Franklin52 For This Post:
# 3  
Old 09-28-2010
The point is we dont know how the file is created, all we know is you use an SQL script we have no idea what it does without seeing it...

Last edited by vbe; 09-28-2010 at 01:12 PM.. Reason: typos
This User Gave Thanks to vbe For This Post:
# 4  
Old 09-28-2010
I'm with Franklin. It is a terminal driver issue.

spool in oracle writes a file using a separate fd, meaning it bypasses terminal I/O.
Redirection > takes terminal output from the terminal driver and sends it to a file

[Chapter 41] 41.4 How UNIX Handles TAB Characters

The only way around it is to change the terminal or use spool inside the SQL.
I like changing the SQL code, not the terminal settings, because terminal changes can mess up lots of other things.
This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 09-28-2010
@vbe, Here is the script, nothing fancy

Code:
set termout off;
set linesize 1938;
set pagesize 0;
set trims off;
set feedback off;

select
CASE WHEN col1 IS NULL THEN rpad(' ', 1) ELSE rpad(trim(col1), 1) END ||
CASE WHEN col2 IS NULL THEN rpad(' ', 9) ELSE rpad(trim(col2), 9) END ||
CASE WHEN col3 IS NULL THEN rpad(' ', 12) ELSE rpad(trim(col3), 12) END ||
CASE WHEN col4 IS NULL THEN rpad(' ', 9) ELSE rpad(trim(col4), 9) END ||
CASE WHEN col5 IS NULL THEN rpad(' ', 12) ELSE rpad(trim(col5), 12) END ||
CASE WHEN col6 IS NULL THEN rpad(' ', 33) ELSE rpad(trim(col6), 33) END x
from test_table
where col = '99';

 exit;

@ jim mcnamara
I'm relatively new to UNIX, can you spool to a UNIX directory from within a SQL script? If so, how? That's what I wanted to do in the first place but my co-workers said it's not possible.

Thanks
# 6  
Old 09-28-2010
You can use the Oracle "SPOOL" command from SQL on a unix server.
It is no different from other platforms.
The "SPOOL" method is much better than using unix Shell commands to redirect output intended for a screen to a file.


Code:
SPOOL filename
...
... sql statements
...
SPOOL OFF

This User Gave Thanks to methyl For This Post:
# 7  
Old 09-28-2010
Thanks to all...

Tried the spool and it works. I guess I just learned a valuable lesson... My co-workers pretendto know UNIX. Next time I won't take what they say as gospel and try it for myself, which is what i usually do. I don't know what came over me. Smilie
This User Gave Thanks to dortoh For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use parameter expansion over a parameter expansion in bash.

Hello All, Could you please do help me here as I would like to perform parameter expansion in shell over a parameter expansion. Let's say I have following variable. path="/var/talend/nat/cdc" Now to get only nat I could do following. path1="${path%/*}" path1="${path1##*/}" Here... (8 Replies)
Discussion started by: RavinderSingh13
8 Replies

2. Shell Programming and Scripting

Tilde expansion

(Using Bash 4.4) When I write something like dir="~/dox" ls $dir then I get the message that the directory '~/docs' does not exist. I understand that the tilde is not expanded at the time of the above assignment because of the quotes. But why is it not expanded at the time when the ls command is... (2 Replies)
Discussion started by: Ralph
2 Replies

3. UNIX for Dummies Questions & Answers

Expansion within cp

I have a bunch of files which I need to transfer to another location... and some of these I need to skip. For e.g. let us say the files are: cust_abc.dat cust_xyz.dat cust_def.dat and I only want to move the first two. I want to do something like: cp cust_.dat <target> ... (1 Reply)
Discussion started by: jawsnnn
1 Replies

4. UNIX for Dummies Questions & Answers

Rewriting line with tabs creating problem

Hi I have an input file which have random file in between.I have to manipulate each line and replace the character from position 5-10 with XXXXXX. But when I am writing this to on output file the tabs in between gets converted to normal space. Input file : 14207531131040896334R108 ... (4 Replies)
Discussion started by: akashtcs
4 Replies

5. Shell Programming and Scripting

Need to print the expansion of the found string (the expansion is beween two delimiters '-' , '||'

Hi , could anyone help me out with this problem. sample.txt has this content : u001- this is used for project1 || u002- this is used for p2|| not to be printed u003- this is used for project3 || u004- this is used for p4 || u005- this is used for project5 || u006- this is used for p6... (9 Replies)
Discussion started by: Balaji PK
9 Replies

6. UNIX for Dummies Questions & Answers

Problem with White spaces and tabs

Hi All, I am facing issues converting white spaces and tabs together in a file I am reading. Here is the command I am trying: tr -s ' '@ | sort -t@ +1n filename I guess the problem is that it is not converting the tabs to another delimiter. Also, I am supposed to accomplish this only using... (5 Replies)
Discussion started by: sh_kk
5 Replies

7. Shell Programming and Scripting

Brace expansion problem in Bash

I have a script that takes an option for server pools to run the script against. The option is given as a comma separated list (ie, -p 201,204,301). I'm using eval and brace expansion to get those pool numbers into an array. It works fine unless only 1 pool number is given. Here's the code: ... (5 Replies)
Discussion started by: mglenney
5 Replies

8. UNIX for Dummies Questions & Answers

sudo and expansion

Hi there, Can anyone explain me the following behavior? hfserver:~# ls -l /home/cronlogs/mysqldump* -rw-r--r-- 1 root root 10658464 2009-01-18 03:00 /home/cronlogs/mysqldump_20090118030002 -rw-r--r-- 1 root root 10651035 2009-01-19 03:00 /home/cronlogs/mysqldump_20090119030001 -rw-r--r-- 1... (4 Replies)
Discussion started by: chebarbudo
4 Replies

9. Shell Programming and Scripting

~ expansion in printf

Hi, I have a script that at one point prints to a file as follows: printf -- $2 > ~/.mydir/$1 The idea is to print to a hidden directory .mydir in my home directory. I've already sanitized the inputs and $1 is in the format path1/path2/filename and $2 is some user input. When I run this... (2 Replies)
Discussion started by: Rledley
2 Replies

10. Shell Programming and Scripting

Pattern expansion problem

All, I have a shell script which executes the below command find $1 -name $2 -print > ${Backup}/FileFind.txt I have $2 sometimes coming with the below values. .* When I go to the log after the execution of the script, .* gets expanded to .developer.adm instead of searching for all... (5 Replies)
Discussion started by: njoshi
5 Replies
Login or Register to Ask a Question