Help parsing filename with bash script

Hi all!

Looking for some help parsing filenames in bash. I have a directory full of files named "livingroom-110111105637.avi". The format is always date and time (yymmddhhmmss). I'm looking to parse the filenames so they are a little more easily readable. Maybe rename them to "livingroom-110111-10.56.37" or maybe "livingroom-2011.Jan.11-10.56.37". Any advice would be great!!

Thanks in advance!

Example with GNU awk on Linux:

$> echo livingroom-110111105637.avi| awk -F[-.] '{d=substr($2,0,6); h=substr($2,7,2); m=substr($2,9,2);s=substr($2,11,2); print $1"-"d"-"h"."m"."s"."$3}'
livingroom-110111-10.56.37.avi

If "-" is not always the delimeter between name and date/time, you might want to modify this to your needs.

1 Like

Amazing! Thank you very much! Looks like it's off by 1 position though, the 7 at the end is cut off, the output for that example should be "livingroom-110111-10.56.37.avi"

 echo livingroom-110111105637.avi | sed -r 's@(.*-......)(..)(..)(..)@\1-\2.\3.\4@' 
1 Like

Wow, you guys are quick! Thanks again!