date is not getting the filedate value.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers date is not getting the filedate value.
# 8  
Old 08-03-2005
Quote:
Originally Posted by vgersh99
I think you need to revisit your logic and reconcile your description with what's been coded.

Again....
Code:
# assigns the value of the variable 'filedate' to the variable 'date'
date=$filedate

# assigns CURRENT time to the variable 'fdate'
fdate=`date +%Y%m%d%H%M%S`

Check this out. I am extending the above code and following the reply I gave to this post of yours.

Code:
# You should be having $filedate with you.

fdate=$(date --date="$filedate" +%Y%m%d%H%M%S)


sh-2.05b$ echo $filedate
Jul 26 09:53
sh-2.05b$ echo $fdate
20050726095300
sh-2.05b$ date +%Y%m%d%I%M%S
20050802090020



Vino
# 9  
Old 08-03-2005
I get the following error when I try the following (I am using kshell):

Code:
# You should be having $filedate with you.
fdate=$(date --date="$filedate" +%Y%m%d%H%M%S)


output...........................
date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te= Jul 21 00:54
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]


As far as your previous post Vino I think I misinterpreted your solution and if you see the solution at the end of that post you will know what I mean. That was working at the time but it isn't now. I don't know why that's why I had to figure it out again.

thankYou
# 10  
Old 08-03-2005
I guess you would need to write a function that parses

Jul 26 09:53 into

20050726095300

vino
# 11  
Old 08-03-2005
Vino, Just out of curiosity, so how did the code work for you? What env. were you using.
# 12  
Old 08-03-2005
You encountered

date: illegal option -- -
date: illegal option -- d
date: invalid argument -- te= Jul 21 00:54
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]


That looks like a solaris m/c.

I am on RH.

uname -a
Linux xxxxx 2.4.21-27.ELsmp #1 SMP Wed Dec 1 21:59:02 EST 2004 i686 i686 i386 GNU/Linux.

Vino.
# 13  
Old 08-03-2005
I am on
SunOS ussun0s 5.8 Generic_108528-22 sun4u sparc SUNW,Ultra-Enterprise-10000
# 14  
Old 08-03-2005
Check this out.

Wrote a little script. My first one in ksh Smilie

Let me know if it breaks.

Code:
#! /bin/ksh
# radhika.sh
#set -x
typeset -R4 YEAR=0000
typeset -R2 MON=00
typeset -R2 DAY=00
typeset -R2 HOUR=00
typeset -R2 MIN=00
typeset -R2 SEC=00

[[ $# -eq 0 ]] && echo " Need some arguments " && exit 0

DATE="$@"

function getmonth
{
case "$mon" in
"Jan") MON=01 ;;
"Feb") MON=02 ;; 
"Mar") MON=03 ;;
"Apr") MON=04 ;;
"May") MON=05 ;;
"Jun") MON=06 ;;
"Jul") MON=07 ;;
"Aug") MON=08 ;;
"Sep") MON=09 ;;
"Oct") MON=10 ;;
"Nov") MON=11 ;;
"Dec") MON=12 ;;
*)      ;;
esac
}

function gettime
{
HOUR=$(echo $TIME | awk -F: '{ print $1 }')
MIN=$(echo $TIME | awk -F: '{ print $2 }')
SEC=$(echo $TIME | awk -F: '{ print $3 }')
}

for val in $DATE
do
case $val in
[A-Z][a-z]*) mon=$val ;;
[1-2][0-9][0-9][0-9]) YEAR=$val ;;
[0-2]*[0-9]*:[0-5]*[0-9]* ) TIME=$val ;;
[0-2][0-9] ) DAY=$val ;;
*) echo "This will never get printed" ;;
esac
done

getmonth $mon
gettime $TIME

#If no year is provided, get it from date +%Y
[[ $YEAR -eq 0 ]] && YEAR=$(date +%Y)

echo $YEAR$MON$DAY$HOUR$MIN$SEC

The test run gave me this.

[~/temp]$ ./radhika.sh Jun 25 09:54:23
20050625095423


And this also

[~/temp]$ DATE="Jun 25 09:54:23"
[~/temp]$ ./radhika.sh $DATE
20050625095423


Vino
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

4. Shell Programming and Scripting

File Count Based on FileDate using Shell Script

I have file listed in my directory in following format -rwxrwxr-x+ 1 test test 4.9M Oct 3 16:06 test20141002150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 4 16:06 test20141003150108.txt -rwxrwxr-x+ 1 test test 4.9M Oct 5 16:06 test20141005150108.txt -rwxrwxr-x+ 1 test ... (2 Replies)
Discussion started by: krish2014
2 Replies

5. 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

6. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

9. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

10. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies
Login or Register to Ask a Question