CSV File Creation Within Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CSV File Creation Within Shell Script
# 1  
Old 07-18-2014
CSV File Creation Within Shell Script

Hi All,

I am trying to create a CSV file within a shell script test.ksh and the code snippet is something like below:

Code:
#!/usr/bin/ksh

# Set required variables.
. $HOME/.prof

# Output file path
Group1=/tmp/G1.csv
Group2=/tmp/G2.csv
Group3=/tmp/G3.csv

$ORACLE_HOME/bin/sqlplus -s $UNAME << EOF 
  WHENEVER SQLERROR EXIT FAILURE
  SET FEEDBACK OFF
  SET ECHO OFF
  SET VERIFY OFF
  SET HEADING OFF
  SET SERVEROUTPUT ON
  SET TRIMSPOOL ON
  SET PAGESIZE 0
  SET NEWPAGE NONE
  set linesize 10000
  set pagesize 1000
  set colsep ","
  set trimspool on
  SPOOL $Group1

select...
from...
where...

SPOOL OFF
EXIT
EOF

The same logic is followed for the other two files as well. But when the script is run, G1.csv gets created but gives the following message for the other two:

Code:
./test.ksh
/tmp/G2.csv: No such file or directory
/tmp/G3.csv: No such file or directory

The second time when run, G2.csv gets created but for the third file I get:

Code:
./test.ksh
/tmp/G3.csv: No such file or directory

Subsequent runs give the same message as above and G3.csv doesn't get created at all.

Am not able to understand what's wrong hereSmilie Any help would be greatly appreciated.
# 2  
Old 07-18-2014
what do you want us to correct?
You haven't provided the complete script...We dont see where you are calling G2 and G3
# 3  
Old 07-18-2014
Is there meant to be a loop in this somewhere to use G2 & G3?

Did you know you can make the script easier to read by adjusting your PATH variable like this:-
Code:
PATH=$PATH:$ORACLE_HOME/bin

You can then just call sqlplus as a simple command.




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

2. Shell Programming and Scripting

File creation , csv

Dear All, Below is my requirement. Scenario: There are four file input.txt, object.txt, output.txt, another_object.txt Now the number of records in all these file may be different. Sample Content of Files: Object.txt -- > abcd.txt (eof) Input.txt --> abc.txt \n... (10 Replies)
Discussion started by: TechGyaann
10 Replies

3. Shell Programming and Scripting

Fixed Width file creation from csv

Hello All, I'm able to achieve my goal of creating a fixed width file from a comma delimited but I know I'm not doing it as efficiently as possible. Original File checksab 004429876883,O,342040,981.98,10232014 004429876883,O,322389,2615.00,10232014... (6 Replies)
Discussion started by: aahlrich
6 Replies

4. Shell Programming and Scripting

Format CSV file from a shell script

I have a shell script which creates a CSV files. there are 3 fields, field1, field2 and comp. I will generates the values for field1 and field2 and Want to compare both. If field1>filed2 then comp should be success written in green in CSV file, else it should fail in red color. How can I change the... (5 Replies)
Discussion started by: sauravrout
5 Replies

5. Shell Programming and Scripting

Reading a csv file using shell script

Hello All, I have a csv file that looks like below ProdId_A,3.3.3,some text,some/text,sometext_1.2.3 ProdId_B,3.3.3,some text,some/text,sometext_1.2.3 ProdId_C,3.3.3,some text,some/text,sometext_1.2.3 ProdId_A,6.6.6,some text,some/text,sometext_9.9.9 I will get ProdId from... (5 Replies)
Discussion started by: anand.shah
5 Replies

6. UNIX for Dummies Questions & Answers

Help to parse csv file with shell script

Hello ! I am very aware that this is not the first time this question is asked here, because I have already read a lot of previous answers, but none of them worked, so... As said in the title, I want to read a csv file with a bash script. Here is a sample of the file: ... (4 Replies)
Discussion started by: Grhyll
4 Replies

7. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

8. UNIX for Advanced & Expert Users

format csv file using shell script

i have a report.csv file from oracle datavase In that file data is like this with report heading and date SALES DAILY REPORT DATE: 06-26-2007 REPORT NAME: SALES DATA AA.BB.CCCC.DDDD,BBBBB,06-26-2007,0,BEGIN,END ZZ.VV.DDDD.XXXXXXX,MMMMMM,06-25-2007,18,BEGIN,END... (3 Replies)
Discussion started by: raosurya
3 Replies

9. Shell Programming and Scripting

Help in parsing a CSV file with Shell script

I have a CSV file which contains number series as one of the fields. Some of the records of the field look like : 079661/3 I have to convert the above series as 079661 079662 079663 and store it as 3 different records. Looking for help on how to achieve this. Am a newbie at Shell... (10 Replies)
Discussion started by: mihirk
10 Replies

10. UNIX for Dummies Questions & Answers

csv file creation

goodpeople... i have following script which collects info from tab and then generates csv file. all is good except 3 digt and 4 digit enties from tab Issue here is that csv file is not okay with 3 digit and 4 digit entries that reside in tab. script... #!/bin/ksh # # Script to send... (2 Replies)
Discussion started by: Student37
2 Replies
Login or Register to Ask a Question