Displaying Column header in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Displaying Column header in shell script
# 1  
Old 05-22-2015
Display Displaying Column header in shell script

Hi,
I need to display specific columns using select statement and spooled to a file and sending it as e-mail. But i am not seeing column header in my output even i use SET HEADING ON.
Code:
//PREDEFINED LOGIN DETAILS
${ORACLE_HOME}/bin/sqlplus -s ${DB_LOGIN}/${DB_PASSWD} <<EOF
SET FEEDBACK OFF
SET HEADING ON
spool /tmp/OUTPUT.TMP
SELECT column1,column2,column3 FROM table1;
quit
EOF

Later I use cat /tmp/OUTPUT.TMP and send email.

Current Output:
Code:
value1 value2 value3 
value1 value2 value3

Expected O/P:
Code:
column1 column2 column3
value1   value2    value3

Thanks in advance for help...

Last edited by rbatte1; 05-22-2015 at 08:15 AM.. Reason: CODE tags required for output, ICODE tags for in-test code, corrected spelling and case.
# 2  
Old 05-22-2015
Can I suggest something first? Either move the credentials to the next line like this:-
Code:
sqlplus -s <<EOF
${DB_LOGIN}/${DB_PASSWD}
SET FEED......

.... or remove the need altogether by creating an account that validates against the OS user (for a local database)
Code:
CREATE USER OPS$FRED IDENTIFIED EXTERNALLY ..........

... and you can then:-
Code:
sqlplus -s / <<EOF
SET FEEDBACK ......

If you don't, then your credentials will be available to anyone running a simple ps command.

Your described problem might actually be the fact that you are both setting feedback off and running with the -s flag for the sqlplus command that means you don't get the column headings. Another thing you might need to set could be the PAGESIZE value to ensure that you only get the headings once, rather than every 10, 30 or 60 rows or whatever your default PAGESIZE is. The maximum I can set is 50000, where zero, one or two turns them off.

I can't quite get the same output issue as you though. I'm using Oracle 11 on RHEL.



Robin
This User Gave Thanks to rbatte1 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

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies

2. Homework & Coursework Questions

Command combination for displaying header and content

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You are given a ANSI text file (a.txt) in the following format and with the following contents-: NAME ROLL... (7 Replies)
Discussion started by: sreyan32
7 Replies

3. UNIX for Dummies Questions & Answers

Command combination for displaying header and content

Hi everyone, I have UNIX this semester and I am just getting started with the commands. An interesting question came up while discussing the head and tail commands. Suppose that I have text file with the following data in the following format-: NAME ROLL MARKS Sam 05 ... (2 Replies)
Discussion started by: sreyan32
2 Replies

4. Shell Programming and Scripting

Add column header and row header

Hi, I have an input like this 1 2 3 4 2 3 4 5 4 5 6 7 I would like to count the no. of columns and print a header with a prefix "Col". I would also like to count the no. of rows and print as first column with each line number with a prefix "Row" So, my output would be ... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

5. UNIX for Dummies Questions & Answers

append column and row header to a file in awk script.

Hi! Is there a way to append column and row header to a file in awk script. For example if I have Jane F 39 manager Carlos M 40 system administrator Sam F 20 programmer and I want it to be # name gend age occup 1 Jane F 39 manager 2 Carlos M ... (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

6. UNIX for Dummies Questions & Answers

Rename a header column by adding another column entry to the header column name

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (1 Reply)
Discussion started by: Vavad
1 Replies

7. Shell Programming and Scripting

Rename a header column by adding another column entry to the header column name URGENT!!

Hi All, I have a file example.csv which looks like this GrpID,TargetID,Signal,Avg_Num CSCH74_1_1,2007,61,256 CSCH74_1_1,212007,647,679 CSCH74_1_1,12007,3,32 CSCH74_1_1,207,299,777 I want the output as GrpID,TragetID,Signal-CSCH74_1_1,Avg_Num CSCH74_1_1,2007,61,256... (4 Replies)
Discussion started by: Vavad
4 Replies

8. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

9. Shell Programming and Scripting

Displaying uppercase in shell script

Hi, The user value y/n should get display in upper case printf "$FBOLD\nDo you want to continue?: $FREG" Do you want to continue?: y Though user enters in smaller case y, but it should get display in uppercase Y How it can be done ? With Regards (2 Replies)
Discussion started by: milink
2 Replies

10. Shell Programming and Scripting

Help with Shell Script displaying Directories

I am new to shell programming and have an assignment question which requires me to list the contents of the present working directory in 4 column format and highlight any subdirectories. It then requires me to develop the shell script to accept a directory name as a positional parameter (if no... (11 Replies)
Discussion started by: cjnd1988
11 Replies
Login or Register to Ask a Question