Reputation: 1952
I have a file with 7 columns with caret (^) separator example
ABCD123456^12345678^192.654^02Aug15^12:10:36
I wrote an awk command which will check duplicates
awk '!seen[$0]++' filename
Length of first field should be 10 & second should be 8
awk -f '^' '{ if ((length($1) == 10) && (length($1) == 10)) print }'
Question is
How can I do time validation ([0-9]:[0-9]:[0-9]
)? what awk query
awk -F '^' '$5 ~ [0-9]:[0-9]:[0-9]' print
But this is not working
Date Validation. How can I validate 2 digit day, 3 Char Month & 2 digit year
Decimal Number validation in 3rd field
How can I combine this all in single awk script
Upvotes: 1
Views: 301
Reputation: 786101
You can combine them into one awk command like this:
awk -F '^' 'length($1) == 10 && length($2) == 8 &&
$3 ~ /^[0-9]+\.[0-9]+$/ && $5 ~ /^[0-9]{2}:[0-9]{2}:[0-9]{2}$/ && !seen[$0]++' file
Upvotes: 2