Hi all,
In Oracle, I am using SQL*Plus and selecting all rows in a table and spooling to a file as pipe delimited. I have to use pagesize 0 but unfortunately, using this option excludes the header and I can't get around having it to display the header fields.
So to get around this, I have to create some header file and combine the output from the non-header output and the header only output. This is working fine, I am just curious if there is a shorter version of the command that I am using to create the header line.
Here is what I am doing at the moment.
Below is the header text file doing a describe of the table:
$: cat a.txt
Name Null? Type
----------------------------------------- -------- ----------------------------
USERNAME NOT NULL VARCHAR2(30 CHAR)
ROLENAME NOT NULL VARCHAR2(30 CHAR)
SWITCHROLE NOT NULL VARCHAR2(1 CHAR)
And this is the command that I am using to convert the content of a.txt to a header file
$: awk 'NR > 2' a.txt | awk '{ print $1 }' | grep -v "^$" | paste -d"|" -s - | awk -F"|" '{ printf "%-30s|%-30s|%-15s\n", $1, $2, $3 }' | tee -a a.header.txt
USERNAME |ROLENAME |SWITCHROLE
Then I do a cat a.header.txt a.out.txt > a.xls. Sample a.out.txt is as below:
MICKEY |XX_AR_COLLECTZZ_INQUIRY |N
DONALD |YY_AA_TEAMMBR |N
Final output is as below:
USERNAME |ROLENAME |SWITCHROLE
MICKEY |XX_AR_COLLECTZZ_INQUIRY |N
DONALD |YY_AA_TEAMMBR |N
While what am doing at the moment works fine, just want to know if there is a more shorter way of doing it