0% found this document useful (0 votes)
37 views1 page

What If There Are 2 Fields in The Text File?: Date - D "+5 Day" +"%D ?

This document provides solutions for reading text files with multiple fields per line into variables and calculating the number of days between two dates. It explains that a while read loop can assign fields from each line of a text file separated by spaces to variables. It also shows how to use the date command to add a number of days to a date and calculate the difference between two dates in days by comparing their Unix timestamps.

Uploaded by

sophia khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

What If There Are 2 Fields in The Text File?: Date - D "+5 Day" +"%D ?

This document provides solutions for reading text files with multiple fields per line into variables and calculating the number of days between two dates. It explains that a while read loop can assign fields from each line of a text file separated by spaces to variables. It also shows how to use the date command to add a number of days to a date and calculate the difference between two dates in days by comparing their Unix timestamps.

Uploaded by

sophia khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. what if there are 2 fields in the text file?

ie.
20 dummy1
25 dummy2
.. ..
How to read each line and assign these 2 fields into 2 variables?
Sol:
cat $TESTFILE | while read FIELD1 FIELD2
do
echo "Field 1 is $FIELD1, Field 2 is $FIELD2"
done
The shell will split the line based on your field separator, and put each field into the
variables named. If there are more fields than variables, the last named will contain
the rest of the line.
2 Add Days to Date
Sol :
date -d "+5 day" +"%D ?
d1=$next_run_date-last_run_date "+%s"
d2=$last_run_date "+%s"
d3=(d2-d1)/864000
echo $d3 days dif

You might also like