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 9174921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:49:51+00:00 2026-06-17T16:49:51+00:00

Possible Duplicate: This script wont sort correctly by age I have absolutaly no idea

  • 0

Possible Duplicate:
This script wont sort correctly by age

I have absolutaly no idea how to get this script to sort the info in Birthdays.csv by date of birth.
I know the sort -n command, however i wish to sort the file birthdays.csv by DOB. How would i go about doing this?

The below script gets user info and date of birth and then puts these info a file called “birthday.csv”.

I then need to Sort “birthdays.csv” by date of birth and then display this newly sorted information. I also calculate how old each person is by today’s date. The problem i have is sorting the info in birthdays.csv by date of birth. Can someone let me know how i would do this sort?

The script is below:

a=0
while [ $a -lt 2 ];
do
    echo Please enter a first name
    read firstName
    echo Please enter last name
    read lastName
    echo Please enter phone number
    read phoneNumber
    echo Please enter date of birth - format dd/mm/yyyy
    read dob
    echo "$firstName,$lastName,$phoneNumber,$dob" >> Birthdays.csv
    echo If you would like to add another person press 1 or enter 2 to proceed
    read a
done

    INPUT=./Birthdays.csv
    OLDIFS=$IFS
    IFS=","
    [ -f ${INPUT} ] && while read Name Surname Telephone DOB
    do
                    birthMonth=${DOB:0:2}
                    birthDay=${DOB:3:2}
                    birthYear=${DOB:6:4}

                    currentDate=`date +%d/%m/%Y`

                    currentMonth=${currentDate:0:2}
                    currentDay=${currentDate:3:2}
                    currentYear=${currentDate:6:4}

                    if [[ "$currentMonth" -lt "$birthMonth" ]] || [[ "$currentMonth" -eq "$birthMonth" && "$currentDay" -lt "$$birthDay" ]]
                    then
                            let Age=currentYear-birthYear-1
                    else
                            let Age=currentYear-birthYear
                    fi

            echo "Name : $Name"
            echo "Surname : $Surname"
            echo "Telephone : $Telephone"
            echo "DOB : $DOB"
            echo "Age : $Age"
            echo "##########################################"
done < $INPUT
IFS=$OLDIFS
    echo $DATE

exit 0;
  • 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-17T16:49:51+00:00Added an answer on June 17, 2026 at 4:49 pm

    add this line

    sort -o $INPUT -n -t , -k4.7,4 -k4.4,4.5 -k4.1,4.2 $INPUT
    

    After

    INPUT=./Birthdays.csv
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Get first day of week in PHP? i have this script that
Possible Duplicate: Initialize script I have a page (Page1.html) and in this page a
Possible Duplicate: Find and list duplicates in Python list I have this script in
Possible Duplicate: jQuery ajax return value I have this jQuery script: $('#headerSubmit').click(function() { var
Possible Duplicate: HTML Text Input allow only Numeric input I used this script function
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Possible Duplicate: Why do this Ruby object have two to_s and inspect methods that
Possible Duplicate: Why does this integer division yield 0? I have a C header
Possible Duplicate: Reference - What does this symbol mean in PHP? I have a
Possible Duplicate: Simple PHP Mailer Script i run a small website and we have

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.