Issue
need to write a script to check if a specific files list are present or not in a directory
files in directory /dir look_like
ABC_YYYYMMDD_EF.txt
/>
GHI_YYYYMMDD_LM.txt
and list has names like
l=[ABC_EF, GHI_LM,PQR_ST,..]
so have to ignore YYYYMMDD which can be anydate in this format ,can anyone tell should we use grep or regex and how
like output: \
ABC_EF FOUND
GHI_LM FOUND
PQR_ST NOT FOUND
Thanks
Solution
$ cat tst.sh
#!/usr/bin/env bash
shopt -s extglob nullglob
dir="$1"
names=( ABC_EF GHI_LM PQR_ST )
for name in "${names[@]}"; do
files=( "${dir}/${name%_*}_"+([0-9])"_${name#*_}.txt" )
(( ${#files[@]} )) && result="" || result="NOT "
printf '%s\t%sFOUND\n' "$name" "$result"
done
$ ls tmp
ABC_19001231_EF.txt GHI_20200102_LM.txt
$ ./tst.sh tmp
ABC_EF FOUND
GHI_LM FOUND
PQR_ST NOT FOUND
Answered By - Ed Morton Answer Checked By - Marie Seifert (WPSolving Admin)