Year Month day from file name in shell script

Posted by user3319390 on Server Fault See other posts from Server Fault or by user3319390
Published on 2014-06-10T10:03:11Z Indexed on 2014/06/11 3:29 UTC
Read the original article Hit count: 417

Filed under:
|
|

I hava file names like below

adn_DF9D_20140515_0001.log
adn_DF9D_20140515_0002.log
adn_DF9D_20140515_0003.log
adn_DF9D_20140515_0004.log
adn_DF9D_20140515_0005.log
adn_DF9D_20140515_0006.log
adn_DF9D_20140515_0007.log

i want get the year, Month, day from file name and create directories

Ex: [[ ! -d "$BASE_DIR/$year/$month/$day" ]] && mkdir -p "$BASE_DIR/$year/$month/$day";

How to achieve this and share the ideas/ script appreciate to you

© Server Fault or respective owner

Related posts about scripting

Related posts about shell-scripting