|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!!! ![]() |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
How are you printing the results out?
Can you please paste the code you are using? --ahamed |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
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... |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Try -e with echo Code:
echo -e $result_set > results.csv --ahamed |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Try: Code:
echo "$result_set" > results.csv -or- Code:
printf "%s\n" "$result_set" > results.csv |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
Learner 20 (03-06-2012) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
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... |
| Sponsored Links | ||
|
|
![]() |
| Tags |
| exporting the output to an excel file |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| generating report in Excel(Open office) using shell scripting | shubham8787 | Shell Programming and Scripting | 1 | 06-02-2011 04:26 PM |
| Creating a file to export into Excel | Nacnud | OS X (Apple) | 2 | 03-14-2011 09:53 PM |
| Export SQL results to .TXT file for emailing | alpinescott | Shell Programming and Scripting | 2 | 08-24-2010 02:19 PM |
| Need to convert the content of file into COLUMN (To export into excel) | velocitnitin | Shell Programming and Scripting | 6 | 12-07-2009 12:26 AM |
| Export to Microsoft excel using shell script | goutam_igate | Shell Programming and Scripting | 1 | 04-16-2009 06:14 PM |
|
|