Skip to main content
added 257 characters in body
Source Link
Stéphane Chazelas
  • 587.8k
  • 96
  • 1.1k
  • 1.7k

date -d is GNU specific. Here, you're running one shell and one datadate command per line, that's terribly inefficient. Do the whole thing in perlperl:

perl -MPOSIX -pe 's{^(\d\d)/(\d\d)/(\d{4})}{ $t = mktime(0, 12, 0, $2, $1 - 1, $3 - 1900); @t = localtime $t; $t -= 86400 * ($t[6] <= 1 ? $t[6] + 2 : 1); strftime("%m/%d/%Y", localtime $t)}e' 

Or with Time::Piece if available:

perl -MTime::Piece -pe 's{^\d\d/\d\d/\d{4}}{ $t = Time::Piece->strptime("$& 12", "%m/%d/%Y %H"); $d = $t->day_of_week; $t -= 86400 * ($d <= 1 ? $d + 2 : 1); $t->strftime("%m/%d/%Y")}e' 

date -d is GNU specific. Here, you're running one shell and one data command per line, that's terribly inefficient. Do the whole thing in perl:

perl -MPOSIX -pe 's{^(\d\d)/(\d\d)/(\d{4})}{ $t = mktime(0, 12, 0, $2, $1 - 1, $3 - 1900); @t = localtime $t; $t -= 86400 * ($t[6] <= 1 ? $t[6] + 2 : 1); strftime("%m/%d/%Y", localtime $t)}e' 

date -d is GNU specific. Here, you're running one shell and one date command per line, that's terribly inefficient. Do the whole thing in perl:

perl -MPOSIX -pe 's{^(\d\d)/(\d\d)/(\d{4})}{ $t = mktime(0, 12, 0, $2, $1 - 1, $3 - 1900); @t = localtime $t; $t -= 86400 * ($t[6] <= 1 ? $t[6] + 2 : 1); strftime("%m/%d/%Y", localtime $t)}e' 

Or with Time::Piece if available:

perl -MTime::Piece -pe 's{^\d\d/\d\d/\d{4}}{ $t = Time::Piece->strptime("$& 12", "%m/%d/%Y %H"); $d = $t->day_of_week; $t -= 86400 * ($d <= 1 ? $d + 2 : 1); $t->strftime("%m/%d/%Y")}e' 
Source Link
Stéphane Chazelas
  • 587.8k
  • 96
  • 1.1k
  • 1.7k

date -d is GNU specific. Here, you're running one shell and one data command per line, that's terribly inefficient. Do the whole thing in perl:

perl -MPOSIX -pe 's{^(\d\d)/(\d\d)/(\d{4})}{ $t = mktime(0, 12, 0, $2, $1 - 1, $3 - 1900); @t = localtime $t; $t -= 86400 * ($t[6] <= 1 ? $t[6] + 2 : 1); strftime("%m/%d/%Y", localtime $t)}e'