[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Unix Script Problem

Posted on 2004-09-23
5
Medium Priority
?
476 Views
Last Modified: 2010-04-21
This script retrun values into a txt file. I need to insert a delimter "^", Currently the delimiter is only added to the headings. How can I add it to the end of the actual data.

e.g

Val1  val2  val3
ss^  dd^   mm^

select substring(Task_Type,1,10)"Type^",
       substring(Job_Name,1,10)"Jobname^",
       substring(MemName,1,30)"Member^",
       substring(W_Day_Str,1,15)"Week Days^" ,
       substring(Days_Cal,1,10)"Calendar^",
       substring(Group_Name,1,30)"Group^",
       substring(Description,1,60)"Description^",
       substring(Node_Id,1,12)"Data Center^" from def_job

Thanks
0
Comment
Question by:xy15973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Expert Comment

by:pmathinos
ID: 12132625
Change this line to reflect your table/columns and try it:

e.g:
SELECT SUBSTR(NUMDATA,4,4)||'^ '||UPLINK||'^ '||DOWNLINK||'^ '||TOTAL
FROM TEMP_TABLE

will give you:

9480^ 0^ 0^ 0
9478^ 1170^ 58^ 1228
9470^ 0^ 0^ 0
9422^ 0^ 0^ 0
9473^ 0^ 0^ 0
9445^ 1281^ 366^ 1647
9472^ 0^ 0^ 0
9480^ 0^ 0^ 0
9479^ 0^ 0^ 0

pmathinos.
0
 

Author Comment

by:xy15973
ID: 12158757

Will this work?

select substring(Task_Type,1,10)||"^"||Type ,
       substring(Job_Name,1,10)||"^"||Jobname ,
       substring(MemName,1,30)||"^"||Member ,
       substring(W_Day_Str,1,15)||"^"||"Week Days" ,
       substring(Days_Cal,1,10)||"^"||"Calendar",
       substring(Group_Name,1,30)||"^"||"Group",
       substring(Description,1,60)||"^"||"Description",
       substring(Node_Id,1,12)||"^"||"Data Center" from def_job
go
0
 

Accepted Solution

by:
pmathinos earned 800 total points
ID: 12167640
double quotes will not work. Use single quotes to append Strings to columns...

To get the column headers as well use a separate SQL query.

Save the following to an temp.sql file, start your SQL session and type
SQL> @temp.sql
to execute the file...
"output.dat" will contain your '^' - delimited report

-- start of sql file

set heading off
set linesize 100
set feed off
set echo off
set show off
set pagesize 0
set space 0
set trimspool on

SPOOL output.dat

select 'Type'||'^'||'Jobname'||'^'||'Member'||'^'||'Week Days'||'^'||'Calendar'||'^'||'Group'||'^'||'Description'||'^'||'Data Center' from dual;

select      substring(Task_Type,1,10)||'^'||
      substring(Job_Name,1,10)||'^'||
      substring(MemName,1,30)||'^'||
      substring(W_Day_Str,1,15)||'^'||
      substring(Days_Cal,1,10)||'^'||
      substring(Group_Name,1,30)||'^'||
      substring(Description,1,60)||'^'||
      substring(Node_Id,1,12)
from def_job;

SPOOL OFF

-- end of sql file


0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question