How can I read each line in a file into: a vairable for the last field, and a variable for the other fields?

How can I read ach line in a file into two variables: one for the last field, and the the other for the other fields ?

For example, I have a file:

hello world! 10s
It is a good day. 4m
...

I would like to read each line into two variables: one variable contains the time interval at the end of the line, and the other variable contains the fields before it. I was wondering how to do it?

while read line 
do
    ...  # split $line into $message and $interval
    echo "$message"
    sleep "$interval"
done < "$inputfile"

Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *