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:
#!/bin/bash
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" >> birthday.csv
echo If you would like to add another person press 1 or enter 2 to proceed
read a
done
INPUT=./birthday.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 "---------------------------"
echo "Name : $Name"
echo "Surname : $Surname"
echo "Telephone : $Telephone"
echo "DOB : $DOB"
echo "Age : $Age"
echo "---------------------------"
done < $INPUT
IFS=$OLDIFS
echo $DATE
exit 0;
Thank you in advance, all help is most appreciated.