Shell loop by day

Quite often I find that I need to create quick Unix scripts to run a set of commands day by day.  Here’s a template loop I start with: # 1=start date YYYY-MM-DD # 2=end date YYYY-MM-DD CURR_DATE=${1} while [ `date +”%Y%m%d” -d “${CURR_DATE}”` -le `date +”%Y%m%d” -d “${2}”` ] do echo “Processing = ${CURR_DATE}” ## add your commands here… CURR_DATE=`date +”%Y-%m-%d” -d “${CURR_DATE} + 1 day”` done echo “ALL...

Using GREP and SED to replace a string in all files in a directory

Over the years, there have been many times when I’ve needed to replace a string in thousands of files.  Usually this comes from a change in some sort of output standard and we’re converting historical data to match, or worse, a typo was found in a script after output was generated.   This little command has saved me many times: cd /to/my/dir grep -r “some_string” * | xargs sed -i...