awk date and time validation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk date and time validation
# 15  
Old 06-07-2009
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

I tested this procedure and it don't make the reqirured proccess ,duplicated the month and the day in one variable.

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

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

I have red this:
#!/usr/bin/ksh

string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"

oIFS="$IFS"; IFS=';'
set -A str $string
IFS="$oIFS"

echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";

And i need to split a date and time in the following patern: 21/04 14:19:30 to 21 ,04 ,14, 19 ,30, but i don't want to use
oIFS="$IFS"; IFS=';'
and
IFS="$oIFS"
How can i do it?

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

I have red this:
#!/usr/bin/ksh

string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"

oIFS="$IFS"; IFS=';'
set -A str $string
IFS="$oIFS"

echo "strings count = ${#str[@]}"
echo "first : ${str[0]}";
echo "second: ${str[1]}";
echo "third : ${str[2]}";

And i need to split a date and time in the following patern: 21/04 14:19:30 to 21 ,04 ,14, 19 ,30, but i don't want to use
oIFS="$IFS"; IFS=';'
and
IFS="$oIFS"
How can i do it?

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

-----Post Update-----
# 16  
Old 06-07-2009
Try...
Code:
$ echo '21/04 14:19:30' | awk 'BEGIN{FS="[^0-9]";OFS=", "};$1=$1'
21, 04, 14, 19, 30

Also...
Code:
$ if touch -t $(echo '21/04 14:19:30' | tr -dc "[0-9]") file1 2> /dev/null; then echo okay; else echo not valid; fi
okay

# 17  
Old 06-08-2009
Again how can i split a tring to sub strings when the string for example is 21/4 to 21 ,4 and 14:20:06 to 14 20 06?
# 18  
Old 06-08-2009
Code:
echo "21/04/2009 14:20:06" | awk -F"[:/]" '{ print $1 }'

# 19  
Old 06-08-2009
That is the case in direction for the last replay i want a shell script to get from the user when it is called at least two strings then in the script pass it over to a awk script and to check how many arguments have been passed.
I use awk -F"[: /:]" to seperate the string that have been passed by the user to sub strings ,and i think using them in the awk script is ok of $1,$2...
How can i do it?
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