How to grave the Date from this command in bash script -


!/bin/bash  # when match not found, present nothing. shopt -s nullglob  # match .wav files containing date format. files=(*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*.wav)  if [[ ${#files[@]} -eq 0 ]]; echo "no match found." fi  file in "${files[@]}"; # date part part file_date='' # sleep parts. ifs="-." read -ra parts <<< "$file" t in "${parts[@]}";         # break loop if match found     if [[ $t == [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]];         file_date=$t         break     fi done # if value not assigned, show error message , continue next file. # making sure there nothing in array , date before moves on if [[ -z $file_date ]];      continue fi  file_year=${file_date:0:4} file_month=${file_date:4:2}     mkdir -p "$file_year/$file_month"  # -- there not interpret filenames starting - options.  echo "moving: ./"$file "to: " "./"$file_year"/"$file_month mv  "$file" "$file_year/$file_month" done 

now there files need date gra date , move now. example there file called meetme.. wav file , have dir yyyy/mm , move thoses files without yyyymmdd in file name already

if you're writing program information, might prefer seconds-since-epoch , use date date in desired format.

$ date -d @$(stat --format='%y' testdisk.log) +%y%m%d 20130422 

you can ascii representation, , manipulate string.

$ stat --format='%y' testdisk.log  2013-04-22 09:11:39.000000000 -0500 $ date_st=$(stat --format='%y' testdisk.log) $ date_st=${date_st/ */} $ date_st=${date_st//-/} $ echo ${date_st} 20130422 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -