- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell Script to database
Operating System - HP-UX
1752587
Members
4480
Online
108788
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2003 09:54 AM
тАО07-03-2003 09:54 AM
Shell Script to database
Hi All,
When I do a select in my data base I got the result below, but I??d to use the fields in order to compare.
The problem is that I have a lot of blank spaces, I??m using set colsep ";" in order to have the columns separated.
1 - How can I use the fieds, extract the data ?
2- How to organize the query result ? Remove the blanks and well formated ?
SQL> select ascii(GRP_BEP),SNPUPDT,DYNUPDT,A_OD_REF,A_PRV_ID,
A_SUB_ID,CMMAD,CMM,CMMNB,CMMNM,CMMST,CMMZIP,
CURCRED,CUS_NBR,CUSTID,DATEBLO,DATEFIN,ascii(F_TARP),ascii(FRST_ACC),LAST_CCA,MAX_CRED,MN15,NB_CCA,RI,
ASCII(STA),TASERQU,USR_PIN from custlc where cus_nbr is not null and ascii(state)=0;
0; 180545248;01-JUL-03; 0;0 ;
00047234580344 ;
CE ; ; 3124800;852697013 ;47382 ;17/09/2003
19/07/2003; 0; 0;25/06/2003; 3127600;852697013
1; 47382; ##########; 1;
0; 180699629;03-JUL-03; 0;0 ;
00043461980315 ;
SILVIA HELENA CORREA RODRIGUES
CE ; ; 691600;854693827 ;12976 ;05/10/2003
06/08/2003; 0; 0;01/07/2003; 2500000;854693827
3; 12976; ##########; 1;
0; 179276618;09-JUN-03; 0;0 ;
BRUNO LEONARDO - CGR TESTE ;
If you never try, never will work
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2003 10:29 AM
тАО07-03-2003 10:29 AM
Re: Shell Script to database
Hi, I'm not 100% sure I understand your question. The best way to do this is to get the perl DB add on for your database.
BUT
if you want to seperate out the fields
awk -F";" '{print $1}'
The above will print the first column using ; as the delimeter.
If you want to further format the answers (from within a script) use printf, either within or outside awk.
e.g.
unload to "output.txt" select cust_name, age, height, bank_balance from table delieter ";";
and you can use a script (one-liner) to print out thses results like so:
awk -F ";" '{printf"%12s %4d %4d %12.2f\n", $1, $2, $3, $4}' output.txt
Regards
Tim
BUT
if you want to seperate out the fields
awk -F";" '{print $1}'
The above will print the first column using ; as the delimeter.
If you want to further format the answers (from within a script) use printf, either within or outside awk.
e.g.
unload to "output.txt" select cust_name, age, height, bank_balance from table delieter ";";
and you can use a script (one-liner) to print out thses results like so:
awk -F ";" '{printf"%12s %4d %4d %12.2f\n", $1, $2, $3, $4}' output.txt
Regards
Tim
-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-03-2003 10:33 AM
тАО07-03-2003 10:33 AM
Re: Shell Script to database
I suspect tht the reason you have received no help (or from your Perl question either) is that you seem unwilling to at least make an attempt at a script.
Awk is probably a little easier to grasp/use so here is a START:
Create a little awk script, my.awk
{
if (length($0) > 0)
{
n = split($0,array,";")
printf("%s %5s %-8.8s\n",array[1],array[2],array[3])
}
}
This will print the first three fields (separataed by semicolons and format them as strings)
Now feed the output of your SQL to awk,
sqlplus .... | awk -f my.awk
OR
awk -f my.awk < spool.out
Awk is probably a little easier to grasp/use so here is a START:
Create a little awk script, my.awk
{
if (length($0) > 0)
{
n = split($0,array,";")
printf("%s %5s %-8.8s\n",array[1],array[2],array[3])
}
}
This will print the first three fields (separataed by semicolons and format them as strings)
Now feed the output of your SQL to awk,
sqlplus .... | awk -f my.awk
OR
awk -f my.awk < spool.out
If it ain't broke, I can fix that.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP