awk date and time validation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk date and time validation
# 8  
Old 05-31-2009
Could somebody anwser?

-----Post Update-----

Could somebody anwser?
# 9  
Old 06-02-2009
Quote:
To check if February connection to the year is ok ,the value of the day according to any month ,the value of the month and simularlly like this to do for the time.
I know that in a foreign language, it is difficult to express exactly what you want.

You want input as "dd/mm". So today would be "02/06", correct? Then you want to make sure 02 is a valid day in 06?

Say you get "ddmm" and "hhmmss" as variables in your shell-script. (How you get them is up to you.)

Code:
DD=${ddmm%/*}
MM=${ddmm#*/}
hh=${hhmmss%%:*}
mmss=${hhmmss#*:}
mm=${mmss%:*}
ss=${mmss##*:}
echo $DD-$MM  $hh:$mm:$ss

So now you have it separated into parts. So now you just have to figure out if it's valid:
Code:
let invalid=0
case $MM in 
  02) 
          test $DD -le 29 || invalid=1 ;;
  0[469]|11) 
          test $DD -le 30 || invalid=1 ;;
  0[13578]|1[02]) 
          test $DD -le 31 || invalid=1 ;;
  *)
          invalid=1 ;;
esac

Note, I haven't tested this, so you better validate this before you use it in anything important.
# 10  
Old 06-02-2009
What with the case of year that february has 28 days?

-----Post Update-----

IN did it could be 28 or 29.

-----Post Update-----

IN did it could be 28 or 29.
# 11  
Old 06-02-2009
Yeah, but they're not providing the year.
# 12  
Old 06-03-2009
In my script the year is taken automatically by the computer without any input needed of year.
# 13  
Old 06-03-2009
Fine then. Just use standard algorithms to determine if the year is a leap year. If so, 29 is ok. If not, 28 is. Every 4 years from now is a leap year until 2100, which isn't.
# 14  
Old 06-03-2009
You could use use touch...
Code:
$ if touch -t 0902290000 file1 2> /dev/null; then echo okay; else echo not valid; fi
not valid

$ if touch -t 0902280000 file1 2> /dev/null; then echo okay; else echo not valid; fi
okay

If using awk...
Code:
$ awk 'BEGIN{if(!system("touch -t 0902290000 file1 2> /dev/null")) print "okay"; else print "not valid"}'
not valid

$ awk 'BEGIN{if(!system("touch -t 0902280000 file1 2> /dev/null")) print "okay"; else print "not valid"}'
okay

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validate date and time in filename by awk

hi i want to validate the date and time in filename filename : mohan.moh.ccyymmdd.ccyymmdd.hhmmss.txt mohan_moh.20151222.20151222.122442.txt i want code that check that date given in filename 20151222 in this format ccyymmdd else it mark file is not valid used in my OS detail is AIX 6... (12 Replies)
Discussion started by: MOHANP12
12 Replies

2. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

3. Shell Programming and Scripting

Access log field - using awk to pull date/time

hey guys. the following line is a line taken from apache's access_log 10.10.10.10 - jdoe "GET /images/down.gif HTTP/1.1" 304 I'm concerned about the field that has the date and time in it. if assuming the delimiter in the file is a space, then the fourth field will always have the date... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

Date validation

File contains below data,how to validate the date using awk command or any command. date formate is fixed as "YYYYMMDD" test1|20120405 test2|20121405 output should be: test1|20120405 Thanks (2 Replies)
Discussion started by: bmk
2 Replies

5. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

6. Shell Programming and Scripting

Date and time range extraction via Awk or analysis script?

Hello does anyone know of an awk that will extract log file entries between a specific date and time range, eg: awk '/15\/Dec\/2010:16:10:00/, /15\/Dec\/2010:16:15:00/' access_log but one that works? Or a free command line log file analysis tool/script? I'd like to be able to view... (2 Replies)
Discussion started by: competitions
2 Replies

7. Shell Programming and Scripting

awk & date time format

This gives: grep "qprt -o -dp -N 1 -P" printfile.log.1216 |awk '{print $7, $9}' |grep lpc1z The output like below: lpc1z /cerner/d_prod/print/ccltemp4235396d030a.dat.tmp.1216075330] lpc1z /cerner/d_prod/print/ccltemp4235396d036a.dat.tmp.1216075634] lpc1z... (2 Replies)
Discussion started by: Daniel Gate
2 Replies

8. Shell Programming and Scripting

AWK and sub/gsub: updating a date/time block

I have a file ("modtest") in which I want to update the last date/time block in the lines beginning with a period. Here is a sample: .ROMULT 10150908EDT 10270908EDT 10010908EDT RANGE RAWV2 1.00 .ROMULT 10150908EDT 10270908EDT 10010908EDT FGROUP CHOWANRV 1.00 .RRIMULT 10150908EDT... (10 Replies)
Discussion started by: chrismcg24
10 Replies

9. UNIX for Dummies Questions & Answers

How Can I Do Time Validation in UNIX

I am very new to scripting in UNIX and in need of help. I am creating a program that will check a file that has a target time in the form of HH:MM:SS before another program can begin executing. The file with the target time will only have that target time in it and nothing else. Is there any... (4 Replies)
Discussion started by: mosammey
4 Replies

10. Shell Programming and Scripting

Time Validation in UNIX?

I am very new to scripting in UNIX and in need of help. I am creating a program that will check a file that has a target time in the form of HH:MM:SS before another program can begin executing. The file with the target time will only have that target time in it and nothing else. Is there any way... (1 Reply)
Discussion started by: mosammey
1 Replies
Login or Register to Ask a Question