The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 10:10 AM
SSH Problem auth problem budrito UNIX for Advanced & Expert Users 1 03-17-2004 10:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-02-2007
zilla30066 zilla30066 is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 13
A Doozy of a problem for me

I have a report I need to format into a nice looking fixed length for each column of output

The report looks like this

1. First Query Title

First Query syntax (select * from tablea)
column1a ,column2a

ROWDATA.......
ROWDATA.......
ROWDATA ......


2. Second Query Title

Second Query syntax (select * from tableb)
column1b ,column2b

ROWDATA ......................................................,ROWDATA
ROWDATA.......................................................,ROWDATA

3. Third Query Syntax

Second Query syntax (select * from tablec)
column1c ,column2c

ROWDATA.................................,ROWDATA
ROWDATA.................................,ROWDATA

As you can see the column width varies from each query result set.
how can I format this report to find the end of each column yes they are all separated by commas and add only one space in order to compact the report.

The dots in each row represents a space

This one is really tough for me
any help is greatly appreciated.


Thanks
  #2 (permalink)  
Old 02-03-2007
aju_kup aju_kup is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 189
i think awk will help you out.... you can use printf to format the report
  #3 (permalink)  
Old 02-06-2007
nhatch nhatch is offline
Registered User
  
 

Join Date: Aug 2002
Location: London, England
Posts: 84
I'm not a great sql person so I normally make a file of the data from the sql statements and then use awk (as sugegsted before) to format how I want it.

I normally put it in a script, a bit like this.

sqlplus -s user/password > a_temp_file <<!
set lin 500
set pages 0
select '~', statement....
....
..;
!

I use the ~ so I can search on it later.

Then with in the same script you can use awk on the a_temp_file to change the format to what you desire. Awk should remove the extra empty spaces.

awk '/~/ {print $1, $2, $3, $4}' a_temp_file > report_file.


You can change the , to <tab> "\t" or any thing else. You can also easily put coloumn names and things like that.

Hope it helps
  #4 (permalink)  
Old 02-06-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,355
You can format the report with sed :
Code:
sed 's/ *,/ ,/g' report
Another way is to modify your Sql query:
Code:
select RTRIM(column1b) || ' ,' || RTRIM(column2b)
from tableb;

Jean-Pierre.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0