You are not logged in.

#1 2014-06-07 09:27:33

Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 9,464

Need to rename files parsing date formats in the filename [SOLVED]

Godaddy changed the naming scheme of their server logs again.  I need some perl or something magic that will convert format A to format B.  Doing this is bash is going to be painful so I'm hoping some of your perl or python ninjas out there could help me.

format A:  ex20140425000001.log
format B: Wed, May 21, 2014.log

So for the example above, that date needs to be converted to this name: ex20140521000001.log

Thanks in advance!

EDIT: nevermind... forgot about date.

for i in *.log; do
	fixeddate="$(echo $i | sed -e 's/,//g' -e 's/^....//' -e 's/.log//')"
	useitdate="$(date -d "$fixeddate" +%Y%m%d%H%M%S)"
	mv "$i" "$newname"

Last edited by graysky (2014-06-07 09:41:59)

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs • 1.21 JIGOWATTS!


Board footer

Powered by FluxBB