?
Solved

Shell script  - increment date variable

Posted on 2011-10-07
4
Medium Priority
?
580 Views
Last Modified: 2012-05-12
Hi,

I need a script that does the following:

I have a table called todo that has a column called date:
The data in it looks like this:
01-SEP-11  

So I have a table with over 3 million rows and some with  01-SEP-11   and some with 02-SEP-11 and so on...

Is there a way to do the following?

for variable=01-SEP-11
do
      output=`sqlplus -s ${db_user}/${db_pass}@${SID} <<!
            set heading off
            set feedback off
            select * from todo where date=${variable};
            exit;
            !`

      echo ${output} >> ultimate_file.txt

**Increment one day at the variable (is there a way to increment a counter for a date? like one day more?
done

=======

Tks,
Joao
0
Comment
Question by:joaotelles
  • 2
4 Comments
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 600 total points
ID: 36935070
Do you mean something like:


for i in $( seq 1 10 ); do v=$( date --date="+$i day" +%d-%b-%Y ); echo $v; done

Open in new window

0
 

Author Comment

by:joaotelles
ID: 36935755
Tks.

So the big picture would be: This would increment the $v, lets say staring form 01-SEP-11 day by day?
Where can set it to start at SEP 01?
And when it comes to 31-SEP.. will it go to 01 OCT?

for i in $( seq 1 10 ); do v=$( date --date="+$i day" +%d-%b-%Y ); echo $v;
output=`sqlplus -s ${db_user}/${db_pass}@${SID} <<!
            set heading off
            set feedback off
            select * from todo where date=${variable};
            exit;
            !`

      echo ${output} >> ultimate_file.txt

done

             

0
 
LVL 48

Accepted Solution

by:
Tintin earned 1400 total points
ID: 36936783
How many days to you want to increment for?

Here's an example starting on Sep 01 and incrementing for 40 days

for i in $(seq 0 40)
do
   date=$(date --date "01-Sep-2011 + $i day" +%d-%b-%Y)
   
   output=`sqlplus -s ${db_user}/${db_pass}@${SID} <<!
            set heading off
            set feedback off
            select * from todo where date=$date;
            exit;
            !`

      echo ${output} >> ultimate_file.txt

done
0
 

Author Closing Comment

by:joaotelles
ID: 36957705
Tks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

864 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