shell scripting to export the results to an excel file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell scripting to export the results to an excel file
# 1  
Old 02-07-2012
shell scripting to export the results to an excel file

Hi,

I am facing issues while exporting the results retrieved from the Database to an excel file.

I have 5 count query in order to count the records in 5 different tables.

I had connected to the DB and retrieved the column count and printed in the screen.

But wat I need to do is, I have to export the count results to an excel sheet which should be saved in my local system.
The format of the output should be:
Column1 Column2
AAAA 10
BBBB 12
CCCC 100

I searched in other threads and it was given as to export all these to a csv file first and then to excel file. I have also exported to csv file but the o/p is not formatted.

It is like AAAA 10 BBBB 12 CCCC 100

Please help!!!Smilie
# 2  
Old 02-07-2012
How are you printing the results out?
Can you please paste the code you are using?

--ahamed
# 3  
Old 02-07-2012
Run the output through xargs first:

Code:
$ echo "AAAA 10 BBBB 12 CCCC 100" | xargs -n2
AAAA 10
BBBB 12
CCCC 100


Code:
$ echo "AAAA 10 BBBB 12 CCCC 100" | xargs -n2 | tr ' ' ,
AAAA,10
BBBB,12
CCCC,100

# 4  
Old 02-07-2012
Here is my coding:

export ORACLE_SID=ABCD
result=`sqlplus -s /NOLOG << EOF
connect username/pass
SELECT count(*) from A;
`

The same way, am collectng all the 5 query's results in 5 different variables and finally printing on the screen using the print statement. Till this it works perfectly..
result_set=`printf "A: %d\n" $result
printf "B: %d\n" $result1
printf "C %d\n" $result2
printf "D: %d\n" $result3
printf "E: %d\n" $result4

`
Now am collectng altogether in result_set (which I think is unwanted) and then exporting this to csv file.
echo $result_set > results.csv

here it prints everythng in a single line...
# 5  
Old 02-07-2012
Try -e with echo
Code:
echo -e $result_set > results.csv

--ahamed
# 6  
Old 02-07-2012
Try:
Code:
echo "$result_set" > results.csv

-or-
Code:
printf "%s\n" "$result_set" > results.csv

This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 02-07-2012
shell scripting to export the results to an excel file

Thanks Scrutinizer & ahamed101,

Both (i)printf "%s\n" "$result_set" > results.csv
(ii) echo "$result_set" > results.csv

is working fine..

Now the output is formatted in the csv file...

Now I need the same to be exported in to an excel file which should be saved in the local PC..

Please give me some idea on that as I am unable to get it from any of the threads...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Export Oracle multiple tables to multiple csv files using UNIX shell scripting

Hello All, just wanted to export multiple tables from oracle sql using unix shell script to csv file and the below code is exporting only the first table. Can you please suggest why? or any better idea? export FILE="/abc/autom/file/geo_JOB.csv" Export= `sqlplus -s dev01/password@dEV3... (16 Replies)
Discussion started by: Hope
16 Replies

2. Shell Programming and Scripting

Export data from database in Excel sheet with the help of Shell script and automated the report

Export data from database in Excel sheet with the help of Shell script and automated the report every day in the mornig. (1 Reply)
Discussion started by: neeraj617
1 Replies

3. UNIX for Advanced & Expert Users

How to export Result to Excel Tabular format from UNIX?

Hi I am working on a script in which I am firing a query on database through Unix and getting the result set. I want to export that in an excel file. I am able to do so nut the result are exported horizontally one below the other. Can anyone plss help me out in exporting the Result in Tabular... (4 Replies)
Discussion started by: Saritau3
4 Replies

4. Shell Programming and Scripting

generating report in Excel(Open office) using shell scripting

Hello All, I need to execute around 15 queries after which all data should come in Excel format. Executing 15 queries is not a problem. Problem is how to present/put data in excel. kindly suggest me how to start, what to study or what should i do. thanks, (1 Reply)
Discussion started by: shubham8787
1 Replies

5. OS X (Apple)

Creating a file to export into Excel

Hello, This is my first post so not sure what response I will get I do have a very small knowledge of UNIX used last over 10 years ago I have recently move over to an Apple IMAC I need to copy all my jpg files into excel Could someone please let me know if this is possible and... (2 Replies)
Discussion started by: Nacnud
2 Replies

6. Shell Programming and Scripting

script to format rows to column and export to excel

i need to write script to copy the txt file to excel. (data can be 2000+), data may not be in order ex: my name: abc age: 20 add: xyz DOB: 17-mar-2010 add1: adf add2: guioth my name: cat age: 35 DOB: 11-oct-2005 city: yeshjl add: opq DOB: 17-mar-2010 add1: atg add2: gth add3:ert ... (2 Replies)
Discussion started by: pjain
2 Replies

7. Shell Programming and Scripting

Export SQL results to .TXT file for emailing

Hi everyone, I am new to unix and bash and in need of some help. I am writing a script that will execute a SQL query. The script runs and the SQl query runs, but I cannot figure out how to save the results as a file that can be emailed to a user. Here is my scripts thus far: #!/bin/sh SID=$1... (2 Replies)
Discussion started by: alpinescott
2 Replies

8. Shell Programming and Scripting

Need to convert the content of file into COLUMN (To export into excel)

I have multiple condition in file as below. MONITOR "ALERT_INFO" DESCRIPTION "Triggered when informational Netware alert occured" MAXTHRESHOLD 95 SEVERITY Normal MONITOR "ALERT_MAJOR" DESCRIPTION "Triggered when major Netware alert occured" MAXTHRESHOLD SEVERITY Major I need to... (6 Replies)
Discussion started by: velocitnitin
6 Replies

9. Shell Programming and Scripting

Export into a single cell of excel sheet...

The awk is giving below output: SELECT divrel.child_org_idn org_main_idn NULL ( VARCHAR(200)) div_nam_2 NULL ( VARCHAR(200)) div_nam_3 NULL ( VARCHAR(200)) div_nam_4 NULL ( VARCHAR(200)) div_nam_5 NULL ( VARCHAR(200)) div_nam_6 NULL ( VARCHAR(200)) div_nam_7 ... (2 Replies)
Discussion started by: goutam_igate
2 Replies

10. Shell Programming and Scripting

Export to Microsoft excel using shell script

I have requirement where i have to export the data extracted from a flat file to a microsoft excel sheet. If the awk returns multiple records then all these records should go in into different rows of same column in excel. Eg. say data returned by excel is A,B,C,D then these 4 records should go... (1 Reply)
Discussion started by: goutam_igate
1 Replies
Login or Register to Ask a Question