Sample text file contains:
04/06/1991 06/05/2001 06/08/2015
cat ".sort.txt" | while IFS='/' read -r num inta intb intc;do
for i in "${ADDR[@]}";do
s=$inta+$intb+$intc
echo $s >> .sort.txt
done
done <<< "$IN"
Expecting the text file to become:
04/06/1991 06/05/2001 06/08/2015 2001 2012 2029
Perl to the rescue:
-apopulates the @F array.-nprocesses the input line by line./, the numbers are summed. Then, the original line ($_) is printed with the new values appended.Note it works for any number of dates per line.