I am relatively new to scripting. I have a file called start_date that has a date in this format (year|month): 1997|08 and a file called end_date that has a date in this format (year|month) 1998|05. I need to increment the dates in between and put them all in a file so that it looks like this...
read startyear startmo <start_date
read endyr endmo <end_date
while [ $work -lt $end ]
work=`expr $work + 1`
if [ $mo -eq 13 ]
work=`expr $work + 88`
As you can see, I have approached the problem slightly differently than you.
First, IFS (internal field separator) is set to |, rather than the default white space.
Read(ing) the input, saves calling an external process (cat).
By creating a single field for the year/month, the year end comparison and update is simplified.
Last edited by kitaman; 09-27-14 at 15:18.
Thank you so very much for the replies. I tried something a little different which seems to work fine. I added the day (01) to the date and then used date -d to calculate the date. Please tell me if this is inefficient or is not a good way to go:
When you add code to a post, use code tags (either highlight the text that is code, and use the # tool in the tool bar, or type "code" without the quotation marks, but with square brackets, at the beginning of the code, and "/code" at the end.
Efficiency is a moving target.
Does your code work? Is it easy to read? Could someone else modify it without coming back to ask questions?
Are you going to run this code once per year or a million times a day?
Do you think that you could simplify your code if you changed the date mask in the date command to "+%Y|%m" ?