I have a csv file with three columns that reads name,postcode,age dd/mm/yy. I would like to calculate the age of each entry from todays date and output to a fourth column of the csv file? I know awk is handy but i dont know to read and write the data from the various column and create a new one!
e.g
name,postcode,dob,age
Dave,ws245f,09/12/2000,13
I have the following input
`cat estimateAge.csv|awk -F'/|,' '{b=mktime($5" "$4" "$3" 00 00 00 00");a (systime()-b)/(365*24*60*60);a=a==int(a)?a:int(a)+1;print $0","a}`'
and this is the output
Joe Bloggs,0121 545465650,01/03/1982,31
The output should be
Joe Bloggs,0121 545465650,01/03/1982,30
Note the age calc is incorrect as the Joe Bloggs is not yet 31 until March
I think the core part of this problem is not adding the new age field to the end. but the age calculation.
try this:
well maybe I should not put them into one line:
test with your example data:
as you can see, I didn’t check the title line, a
NR>1check could easily skip the title. You could DIY.hope it helps