|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
how to know 3 mont's ago date?
i want to search file that is 3 month's ago according the file name..
file name is such ATK_7B1_WIP_20041116160700.1.xml.dat ATK_7B1_WIP_20041116160700.2.xml.dat ATK_7B1_WIP_20041116160700.3.xml.dat ATK_7B1_WIP_20041116160700.4.xml.dat and the proram is like: #!/bin/bash is_older() { DATE=$(date -u "$1" +%Y-%m-%d) TODAY=$(date -u "$(date +%Y-%m-%d) $2 $3 $4 $5" +%s) COMPARE=$(date -u "$DATE" +%s) test $(($TODAY - $COMPARE)) -le 0 && return 1 || return 0 } for FILENAME in ATK_*.dat ; do FILEDATE=$(echo $FILENAME | cut -c 13-20) if is_older $FILEDATE -3 months ; then echo "$FILENAME is older than 3 months." else echo "$FILENAME is younger than 3 months." fi done but there's an error comparing in is_lder function such: date: 0551-402 Invalid character in date/time specification how can i solve this..please |
|
#2
|
|||
|
|||
|
Quote:
Read "man date" carefuly. Your line DATE=$(date -u "$1" +%Y-%m-%d) is not correct. Put set -xv in the beginning of the script and set -x as the first command if the function is_older() and run the script again. You will see the intermediate results and can find the errors. If I were you, I would read (and study) some tutorial of the shell programming. I thing I have solved something similar for you some time ago. Have you tried it? Regards zlutovsky ![]() |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > how to know 3 mont's ago date? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|