Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:44+00:00 2026-06-17T08:18:44+00:00

I have a csv file with three columns that reads name,postcode,age dd/mm/yy. I would

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:18:45+00:00Added an answer on June 17, 2026 at 8:18 am

    I think the core part of this problem is not adding the new age field to the end. but the age calculation.

    try this:

    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}' file
    

    well maybe I should not put them into one line:

    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}' file
    

    test with your example data:

    kent$  echo "Dave,ws245f,09/12/2000"|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}' 
    Dave,ws245f,09/12/2000,13
    

    as you can see, I didn’t check the title line, a NR>1 check could easily skip the title. You could DIY.

    hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file that has genotype counts in three columns. I am
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
I have a CSV file that goes something like this: ['Name1', '', '', '',
I have a csv reader class that reads a .csv file and its values....
I have a CSV file that contains over 80,000 rows and 100 columns. I'm
I have a simple script that accepts a CSV file and reads every row
I have a CSV file that looks like this, where time is a UNIX
I am using FileHelpers to read a CSV file that have hundreds of columns
Little Background: I have csv file which has lots of rows and each row
I have a csv file, and I want to extract the each column a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.