Validate date file format using awk

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate date file format using awk
# 1  
Old 03-24-2014
Validate date file format using awk

Here is my sample data

column 1|columne 2|start Date|end Date

Now in the file i am expecting the date fields should be mm/dd/yyyy format.
How i can validate without open the file data row number 2 and 4 having wrong date format and print the data rows.

Last edited by Don Cragun; 03-24-2014 at 04:19 AM.. Reason: Add CODE tags.
# 2  
Old 03-24-2014

Kindly use the coede tage as per forum rules for any command or code please.
Following may help you for same.

awk  -F"\|" 'BEGIN {print "Showing lines which have issues."} {a=match($3,/..\/..\/.....*/); substr($3,RSTART,RLENGTH)} {if(a==0) {print $0}} {b=match($4,/..\/..\/.....*/); substr($4,RSTART,RLENGTH)} {if(b==0) {print $0}}' check_date_format1211134

Output will be as follows.


NOTE: Where check_date_format1211134 is the input file.

R. Singh

Last edited by RavinderSingh13; 03-24-2014 at 03:44 AM.. Reason: Added code tags suggestion as per forum rules
# 3  
Old 03-24-2014
awk -F'|' -v OFS='|' ' $3 !~ "^(0[1-9]|1[12])/(0[1-9]|[12][0-9]|3[01])/[0-9]{4}$" || $4 !~ "^(0[1-9]|1[12])/(0[1-9]|[12][0-9]|3[01])/[0-9]{4}$" ' file

# 4  
Old 03-24-2014
Thanks RavinderSingh13 and anbu23
# 5  
Old 03-24-2014
awk -F "|" '{match($3FS$4,/..\/..\/....\|..\/..\/..../);printf RSTART==0?$0"\n":x}'  filename

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. Shell Programming and Scripting

Need to change date format in a csv file using awk

Example: Input csv file 00245DLS,Sitel Ocala,12/31/2014,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel Ocala,12/31/2014,19:00,-1.00,-1.00,-1.00,-1.00 00245HB,Charlotte,01/01/2015,00:00,-1.00,-1.00,-1.00,0.00 Output csv file 00245DLS,Sitel Ocala,2014/12/31,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel... (8 Replies)
Discussion started by: adit
8 Replies

3. Shell Programming and Scripting

Need script to validate file according to date

Hi All, I am very new to unix and just started to work with unix and shell scripting.I have a query anyone help would be much appreciated I am using sun solaris OS I want to validate a file according to its date and if validate successful then it would write the file name,size,date and... (3 Replies)
Discussion started by: sv0081493
3 Replies

4. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

5. UNIX for Dummies Questions & Answers

Format Date in awk

I have an assignment in a Linux class I am taking. It has multiple scripts. Basicly when it runs it asks the user name and shows information about the user from the /etc/passwd and /etc/shadow files. The one I need help with is the one that reads the /etc/shadow file. I need to format the date into... (1 Reply)
Discussion started by: kazulk
1 Replies

6. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

7. Shell Programming and Scripting

Validate date format in argument

Hi.. I'm a newbie in KSH. Need help. How can I validate input date format in argument using format mm/dd/yy. Eg. > 12/30/09. Any info/help is highly appreciated. (3 Replies)
Discussion started by: harry0013
3 Replies

8. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

9. Shell Programming and Scripting

Need to validate a date input format

Hi all, I have a shell script(K shell) which takes a date as input. i want the input to be in DD-MM-YYYY format. Can i enforce such a format of input string using just one line of code? OR do i need to parse the input date into different components and test them using Case statements... (2 Replies)
Discussion started by: rajugp1
2 Replies

10. Shell Programming and Scripting

Validate long date format in If statement

Hi, I want to validate if the given input is a valid month (written in long month format) Jan / Feb / Mar / Apr / May / Jun etc etc This is what I've got with || (or statements): #!/usr/bin/ksh INPUT_DATE=$1 FORMATTED_DATE=`date | cut -f2 -d' '` #If there's no input use the... (1 Reply)
Discussion started by: Batsies
1 Replies
Login or Register to Ask a Question