Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to execute the following shellscript with hazel app on any file in the folder. It works, but the only thing thats causing a problem is the date for yesterday.

#! /bin/bash

saveDir="TJ"
dd=$(date --date='yesterday' +'%m-%d-%Y')
for file in *.csv ; do
    saveName="${saveDir}/TJ ${dd}.csv"
    cut -d',' -f2,14 "$file" > "$saveName"
done

Any ideas why it isn't working?

share|improve this question

2 Answers 2

up vote 11 down vote accepted

Try using date like this:

dd=$(date -v -1d '+%m-%d-%y')

as mentioned yesterday is part of GNU Date, but using an offset of -1d should be equivalent for OS X use.

share|improve this answer

The date utility bundled with OS X is not GNU date (which accepts the --date option).

You can use homebrew to install it.

You can probably use Perl to get what you want:

perl -MPOSIX=strftime -le 'print strftime("%d-%m-%Y",localtime(time()-86400))'
# or
perl -MTime::Piece -MTime::Seconds -le 'print((Time::Piece->new - ONE_DAY)->dmy)'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.