Working out days of the week and processing file in 3 working days

Hi guys i need advice on the approach to this one......

I have a file say called
Thisfile.20130524.txt
i need to work out from the date 20130524 what day of the week that was and then process the file in 3 working days. (so not counting saturday or sunday....(will not worry about bank holidays at the moment)

so in this example the 24th was a friday ignore the 25th and 26th being saturday and sunday so i would process the file on the 29th.

so breaking it down

  1. Need to work out from the file name the day of the week
  2. Take the day of the week and count 3 days forward not including the weekends

Can someone suggest how i would approach this? Maybe using the Cal and nawk? Any suggestions would be helpful. I do believe my brain has shutdown and gone on holiday :confused:

#! /bin/bash

f="Thisfile.20130521.txt"

dt=`echo $f | cut -d'.' -f2`
day=`date -d $dt +%a`

if [[ "$day" == "Wed" || "$day" == "Thu" || "$day" == "Fri" ]]
then
    fut_dt=$(( $dt + 5 ))
else
    fut_dt=$(( $dt + 3 ))
fi

date -d "$fut_dt" +"%Y-%m-%d %a"
1 Like

I see what your doing here and that looks like a very easy approach thanks! Thats what i love about unix, i was trying something far far more long winded, so i love your spin on it!