linux - REGEX filename Shellscript check -


i trying write bashscript check using regex distinguish between following files. trying select drlic_info_20170912.out in if statement , not drlic_info_20170912_temp.out. 20170912 daily timestamp.

input filenames:

drlic_info_2017-09-12.out drlic_info_2017-09-12_temp.out 

current check:

search_drlic_info='drlic_info'  if [[ $filename == *$search_drlic_info* ]] 

could please try following , let me know if helps you.

filename1="drlic_info_20170912_temp.out" regex="drlic_info_[[:digit:]]+_temp.out" if [[ $filename1 =~ $regex ]]; echo "file named "$filename1 " found."; else echo "file name " $filename1 " not found."; fi 

or in case want specific date string should have 8 digits in change above regex variable following too.

regex="drlic_info_[[:digit:]]{8}_temp.out 

edit: if want use search_drlic_info variables shown you, try following , let me know then.

search_drlic_info="drlic_info" filename1=$search_drlic_info"_20170912_temp.out" regex="drlic_info_[[:digit:]]{8}_temp.out" if [[ $filename1 =~ $regex ]]; echo "file named "$filename1 " found."; else echo "file name " $filename1 " not found."; fi 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -