Date Calculations using script!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Calculations using script!!
# 1  
Old 09-23-2011
Date Calculations using script!!

Hi all,

Thanks in Advance , i am very new to programming part in script i think using some caluations+ sed command only we can do this process in script.

for exampl:

i have file in that one line is like this

Quote:
between '2011-08-01' and '2011-12-01'
using sed i can replace the date and all but my requirement is

The script runs every friday , suppose if i run this on 10th month means.

the script need to change the value in the file like this


Quote:
between '2011-09-01' and '2012-01-01'
every time the month alone need to change in this date format

Quote:
between 'current month -1month' and 'current month + 3 months'
is this possible need your guidance to solve this thread

Last edited by anishkumarv; 09-23-2011 at 08:01 PM..
# 2  
Old 09-23-2011
Try the shell builtins or awk...sed isnt suited for arithmetic.
# 3  
Old 09-24-2011
Hi,

This is the Exact fiile

Quote:
select b.id as cli_id,b.login as cli_login, b.pname as cli_name, b.cname as cli_company, b.phone as cli_phone, b.email as cli_email, (select (value / 1048576) from Limits where limit_name='disk_space' and id=b.limits_id) as Client_Package, b.cr_date, (select FROM_UNIXTIME(value,"%Y-%m-%d") from Limits where limit_name='expiration' and id=b.limits_id) as Client_expire, If(b.status=0,'Active','Inactive') as Cli_Status, a.name as dom_name, If(a.status=0,'Active','Inactive') as Dom_Package, a.cr_date as dom_create, (select FROM_UNIXTIME(value,"%Y-%m-%d") from Limits where limit_name='expiration' and id=a.limits_id) as dom_expire, (select (value / 1048576) from Limits where limit_name='disk_space' and id=a.limits_id) as Dom_Package, round((a.real_size / 1048576)) as Dom_usage from domains a, clients b where (select FROM_UNIXTIME(value,"%Y-%m-%d") from Limits where limit_name='expiration' and id=a.limits_id and (FROM_UNIXTIME(value,"%Y-%m-%d") between '2011-08-01' and '2011-12-01') ) and a.cl_id=b.id group by a.id;

'2011-08-01' and '2011-12-01'

i need to change this date part alone change every time.

between 'current month -1month' and 'current month + 3 months'

any help using AWK appriciated

---------- Post updated at 11:05 PM ---------- Previous update was at 06:16 AM ----------

Hi all,

I used this commad but still no luck :-(


Code:
sed -i "/between  '2011-08-01' and '2011-12-01'/'between '$(date --date="- 1 month" +%Y-%m)-01' and '$(date --date="+ 3 months" +%Y-%m)-01'/g" /var/tmp/p.sql

With Regard
Anish kumar.V

---------- Post updated at 11:28 PM ---------- Previous update was at 11:05 PM ----------

Code:
sed "s/between[^)]*/between '$(date --date="- 1 month" +%Y-%m)-01' and '$(date --date="+ 3 months" +%Y-%m)-01'/" /var/tmp/p.sql

using this i got the output what i expect :-)
# 4  
Old 09-24-2011
See this thread for the full discussion.

[SOLVED] Date Calculations using script!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date wise calculations?

POST_DATE CHECK_NUMBER TYPE LOGIN_NAME 2015.09.09 XXXXXXXXXX mark XXXXXXXXXX 2015.09.09 XXXXXXXXXX fsadf XXXXXXXXXX 2015.10.05 XXXXXXXXXX defaa XXXXXXXXXX 2015.10.05 XXXXXXXXXX dewe XXXXXXXXXX 2015.10.06 XXXXXXXXXX dqwe XXXXXXXXXX 2015.09.14 XXXXXXXXXX dt4e XXXXXXXXXX... (22 Replies)
Discussion started by: nikhil jain
22 Replies

2. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

3. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

4. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

5. Shell Programming and Scripting

Help with Arithmetic calculations in Shell script

Hi, I need a help with arithmetic calculations in my script. I have two variables: a=17; b=1712 I want to perform ($a/$b)*100 with two decimals in the result. I tried with following: res=$((100*a/b)) res=`echo "scale=2; $a / $b" | bc` But I am not getting the decimal values.... (4 Replies)
Discussion started by: karumudi7
4 Replies

6. Shell Programming and Scripting

bash script range calculations

Hi, I have data in the following form: AB001 10 AB002 9 AB003 9 etc AB200 5 What I need to do is sum up the second value according to groups of the first, i.e. AB001 to AB030 the total being X, AB031 to AB050 the total being Y etc (there are 5 AB ranges of different sizes). I'm sure... (3 Replies)
Discussion started by: chrissycc
3 Replies

7. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

8. Shell Programming and Scripting

Need help with Date calculations in ksh

Hi Gurus, I am writing a script where we enter two dates, one a FROM DATE and the other a TO DATE. I need to validate that difference between the two dates is always less than or equal to 60 days. I could not find any date utility in ksh that could help me with this. Finally, I am deciding... (5 Replies)
Discussion started by: jidsh
5 Replies

9. UNIX for Dummies Questions & Answers

Date Calculations

I need to be able to use the current date and calculate 7 days ago to be stored in another variable to be passed to a file in my Unix shell script. I need the date in the following format: date '+%m/%d/%Y' or 05/16/2006 How do I calculate date minus 7 days or 1 week ago? (8 Replies)
Discussion started by: mitschcg
8 Replies

10. Shell Programming and Scripting

any way to speed up calculations in bash script

hi i have a script that is taking the difference of multiple columns in a file from a value from a single row..so far i have a loop to do that.. all the data is floating point..fin has the difference between array1 and array2..array1 has 700 x 300= 210000 values and array2 has 700 values.. ... (11 Replies)
Discussion started by: npatwardhan
11 Replies
Login or Register to Ask a Question