473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

shell script to extract rows from table

Hi.

I am new to Unix. I need to write a Unix Shell Script to extract records from the table and write those extracted datas to a text file.

DB using is DB2.

Can anyone give me some sample shell script

thanks
Krishnakanth
Sep 30 '08 #1
5 13587
Is there any specific reason that you want a shell script. You can do a export of the table data using EXPORT command.
Oct 1 '08 #2
sakumar9
127 Expert 100+
You can call EXPORT command from a shell script, EXPORT will write the table data into files.
Oct 1 '08 #3
docdiesel
297 Expert 100+
Hi,

Expand|Select|Wrap|Line Numbers
  1. db2 "select a,b,c from schema.mytable" >file.txt
should do, if you don't need the data in CSV format. Use "db2 -x" if you don't want the column heads.

Regards

Doc Diesel
Oct 1 '08 #4
Thanks for your reply. Now I have got another issue.
_________________________
echo "Run SQL select current timestamp from SYSIBM.SYSDUMMY1 with ur" >>$monlog
db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur" >> currenttimestamp
cat currenttimestamp
_________________________

The output what I am getting is as follows:

1
---------------------------------------
2008-10-03-02-00.00.00.000000

1 row(s) selected
=================================

I want only the timestamp to be displayed. which I need to store the timestamp to a variable called currtimestamp.

and I need to pass this currtimestamp to another query as follows.
___________________
db2 "SELECT * FROM BMWDEV1.ZB_RCBL_ERROR WHERE TIMESTAMP_UPDATED >= '2008-10-01-00.00.00.000000' AND TIMESTAMP_UPDATED > currtimestamp WITH UR" >>$monlog
___________________

Can anyone help me out to fix this issue.

Thanks in advance.

Krishnakanth
Oct 3 '08 #5
docdiesel
297 Expert 100+
Hi,

either you use "db2 -x SELECT ..." to suppress the header & footer, or you grep for the leading digit "2" (of 2008...):
Expand|Select|Wrap|Line Numbers
  1. db2 "SELECT ... " | grep ^2 >file.txt
Instead of that you may store the date in a shell variable and use the latter in the next step:
Expand|Select|Wrap|Line Numbers
  1. DTSTAMP=` db2 -x "select ..." `
  2. db2 "select * ... where WHERE TIMESTAMP_UPDATED > '$DTSTAMP' "
  3.  
I guess you need the timestamp of the beginning of the script for more than one action. I'd suggest to create an auxiliary table {var varchar(20), value varchar(128)}, for script internal values:
Expand|Select|Wrap|Line Numbers
  1. insert into my.variables (var,value)
  2.   SELECT 'tstamp', Current_timestamp
  3.   from sysibm.sysdummy1 ;
  4.  
  5. SELECT * from ...
  6. WHERE TIMESTAMP_UPDATED>(
  7.   timestamp(select value from my.variables where var='tstamp')
  8. ) ;
  9.  
Regards

Doc Diesel
Oct 4 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Don Crossman | last post by:
Assume a MYSQL table, foo. One column, bar datetime. Two rows: 2004-01-01 08:00:00 2004-02-01 08:00:00 select * from foo where extract(day from bar)=1; 2 rows in set...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
1
by: sainathr | last post by:
Hi, I would like to run shell scripts with respect to the time mentioned in postgres data base tables. Postgres database should trigger the shell script for the time mentioned in the table. To...
0
by: pankajd | last post by:
hi all, i need an urgent help for writing a shell script which will extract out and print a substring which is the shortest substring from the given string where first and last character of that...
2
sumittyagi
by: sumittyagi | last post by:
Hi All! could you please guide me how to add an option to a shell script, and how to extract that option in the script. For eg. if we give arguments to a script, then we get that argument...
2
Colloid Snake
by: Colloid Snake | last post by:
Hello everyone- I am working on a shell script to parse out a Node.def file that contains the hostname, version, IP address, and date updated. There is a separate .def file for each node (of which...
3
by: regnumber | last post by:
Hi. I am new to Unix. I need to write a Unix Shell Script to extract records from the table and write those extracted datas to a text file. DB using is DB2. Can anyone give me some sample...
4
by: devi thapa | last post by:
Hi, I am executing a python script in a shell script. The python script actually returns a value. So, can I get the return value in a shell script? If yes, then help me out. Regards, Devi
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.