I have a text file (file.txt) which has a date in YYYYMMDD format in the fourth column. I need to compare and check if that date matches the last date of each month in the same format for all the rows.
I have been able to figure out the last date of each month. But now I want to match it with with all the rows of fourth column so that by mistake there is no mismatch in any of the rows. I tried this :
awk -F "|" '{print $4}' file.txt > file1.txt
Is there a way using a single awk command to get what I need or a loop after this to match the row(s)?
Your spec is a bit vague and/or incomplete.
So - you have the string to compare to. Where and how? Variable, file, command substitution? What do you want to do if it doesn't match the fourth field of a line in your file? Print the line? An error msg?
Well, your second sample differs from your first one; let's assume you mean the first one's structure. And, as you didn't say how you provide the comparison string, try and adapt
awk -F "|" -vCOMP='20150430' '$4 != COMP {print $0 ": Date mismatch!"}' file
g|e|f|20150429: Date mismatch!