unix - Shell script: Check if a Directory is of YYYY_MM_DD_HH this format -


i have script creates file list of directories available in path. now, tasks if directory of format "yyyy_mm_dd_hh" in file list.

my file list has following entries:

2014_04_21_01

asdf

2012_01_19_10

2010_01

now move directories names yyyy_mm_dd_hh path. i.e., 2014_04_21_01 & 2012_01_19_10 must moved.

please advise.

use bash regex pattern matching:

for dir in $list if [[ "$dir" =~ ^[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}$ ]]    mv "$dir" newdir/    fi done 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -