Output is not comming as expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output is not comming as expected
# 1  
Old 03-26-2012
Java Output is not comming as expected

Hi All,

I am in middle of one script. I want output in the form of xls file.

There are 4 fields - user name, email Id, full name, date of birth. I want these details to get in seperate columns.

But, i am getting it in the single cell and as like a paragraph.Smilie

Please suggest me some command to format this looks.. Smilie

Thankuz! SmilieSmilie
# 2  
Old 03-26-2012
Mohammed Fareed
# 3  
Old 03-26-2012
Post an example of the input and expected output using code tags, thanks.
This User Gave Thanks to zaxxon For This Post:
# 4  
Old 03-26-2012
Write the o/p as CSV file

Code:
"col1", "col 2", "col 3"

And while opening it as spreadsheet chose proper delimiters..
Or show us what the script prints.. So that it can be corrected.
# 5  
Old 03-26-2012
Code:
#!/bin/bash
ORACLE_HOME=/app/oracle/product/10.0.0.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
x=`sqlplus -s abc_USER/password@abcd.pfizer.com <<EOFSQL
select USERNAME, EMAIL, FULL_NAME, user_bdate from sfuser where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from columnABC)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
EOFSQL`

echo $x>ash_t.xls
uuencode ash_t.cls ash_t.xls | mail mymailid@abc.com

===============================================================
This is the script that i worked on!
I actually want to avoid SPOOL command.

Last edited by methyl; 03-26-2012 at 07:16 AM.. Reason: please use code tags
# 6  
Old 03-26-2012
Environment variables are not files. Your $x is unsuitable for receiving more than one line.

Quote:
I actually want to avoid SPOOL command
Why? It is the sensible approach.
The link in post #2 has some useful tips about how to produce a correctly formatted CSV file.

Convention says use file extension ".csv" (not ".xls"). Only use ".xls" for a genuine old-format Microsoft Excel spreadsheet.
These 2 Users Gave Thanks to methyl For This Post:
# 7  
Old 03-26-2012
Sensitive approach coz.. i tried all the possible ways to work on with spool but script iz nt getting executed..

below is the script that i tried earlier


Code:
#!/bin/bash
ORACLE_HOME=/app/oracle/product/10.0.0.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
sqlplus -s abc_USER/password@abcd.pfizer.com <<EOFSQL
set feedback off
set verify off
set pagesize 0
set term off
set termout off
set heading off
set echo off
SPOOL user.csv
select USERNAME, EMAIL, FULL_NAME, LAST_LOGIN, DATE,CREATED from sfuser where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from scm_authorized_keys)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
SPOOL OFF

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

---------- Post updated at 06:28 AM ---------- Previous update was at 06:19 AM ----------

@zaxxon :

My Input is as like i have mentioned in couple of above posts
And i am seeking out put as :

USERNAME |EMAIL |FULL_NAME | LAST_LOGIN | DATE CREATED
ABC |Abc.com |Abcdef |10th Sep'11 | 10th mar'09

| = seperator in two columns from Excel

---------- Post updated at 06:30 AM ---------- Previous update was at 06:28 AM ----------

Please find my below script using spool command and suggest me some changes..

---------- Post updated at 06:30 AM ---------- Previous update was at 06:30 AM ----------

Please find my below script using spool command and suggest me some changes..

Last edited by vbe; 03-26-2012 at 08:37 AM.. Reason: code tags...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

awk not giving the output expected

Hello, I am practising awk and decided to compare two columns and print the result of the comparison as third column i/p data c1,c2,c3 1,a,b 1,b,b i am trying to compare the last two columns and if they match I am trying to print match else mismatch(Ideally i want that as a last column... (5 Replies)
Discussion started by: mkathi
5 Replies

3. Shell Programming and Scripting

For loop not giving expected output

#cat /tmp/input old_array old_dev new_dev new_array 0577 008AB 01744 0125 0577 008AC 01745 0125 0577 008AD 005C8 0125 0577 008AE 005C9 0125 0577 008AF 005CA 0125 0577 008B0 005CB 0125 0577 008B1 005CC 0125 cat test.sh #!/bin/ksh... (4 Replies)
Discussion started by: mbak
4 Replies

4. Shell Programming and Scripting

awk output not what was expected

Good Moring, I am currently reading about awk in a manual and following the examples using the oratab file. My system is SOLARIS 10 I think I am getting strange behavior judging by what the book says to do and what I am getting with my little program. Here is my program: grep -v oratab |... (4 Replies)
Discussion started by: bdby
4 Replies

5. Shell Programming and Scripting

Grep can't match expected but output all

lyang001@lyang001-OptiPlex-9010:~$ service --status-all |grep dbus acpid acpi-support alsa-restore alsa-store anacron apport atd avahi-daemon bluetooth cgroup-lite console-setup cron cups dbus dmesg dns-clean failsafe-x ... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

6. Shell Programming and Scripting

Trying to learn to use functions in gawk and not getting expected output.

I've been working on improving my awk, and the next thing I want to learn is to properly use functions (I understand functions in shell and python). I have the following code which includes how I did this without functions before, and two attempts I've made to do it with functions: function... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

7. Shell Programming and Scripting

awk - output comming strange: for operator ~ and == .

Hi awk experts, I am getting a strange output , may be it is normal but I am unable to comprehend, When Using == operator it is showing correct: # ls -l | awk '{for (i=0;i<=NF;i++) if ( $i =="info" )print $1,$6,$7,$8,$9}' drwx------ Jan 17 10:44 info But When using ~ (equal )... (4 Replies)
Discussion started by: rveri
4 Replies

8. Shell Programming and Scripting

Not getting expected output

Hi I have written below script to get the data in table form. #!/bin/sh echo "File Name\tType" for i in *; do echo "$i\t\c" if ; then echo "directory" elif ; then echo "symbolic link" elif ; then echo "file" else echo "unknown" fi donehowever i am getting output in different way... (3 Replies)
Discussion started by: scriptor
3 Replies

9. Shell Programming and Scripting

awk not generating the expected output

Hi, I am presently stuck in a csv file. INPUT CSV baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played EXPECTED OUTPUT CSV ... (7 Replies)
Discussion started by: scripter12
7 Replies

10. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies
Login or Register to Ask a Question