vendredi 1 septembre 2017

Applying pre-defined filter on the looped files

I have some bash looping script which loops the files and do some things with them

for pdb in ${output}/*.pdb ; do
name=$(basename "$pdb")
echo "I am sending ${name} to some place!"
done

now I would like to introduce some filter within the loop to pass the files only without some keywords in any part of the $name , thus excluding all files which has the defined keywords.

For the realization I would like to set all keywords in an array

#For a file with that keywords within the name the script should stop and loop another file etc
declare -a keywords=('apo' 'Apo' 'APO' 'sauf');

#workflow for a signle keyword "apo"
 for traj in ${all_trr}/*.xtc; do
 traj_name3=${traj##*/[0-9][0-9]_[0-9][0-9]_[0-9][0-9][0-9][0-9].}
 if [[ "$traj_name" != *apo* ]]
 then
#begins loop from the another file
  echo "I am sending ${traj_name} to analysis"
  #break 
 else
  echo "I am not sending ${traj_name} to analysis"
  continue
 fi
done

So I need to adapt this work-flow for an array: 1) to compare each file name with the array element and 3) send it to the script only if it does not match it. E.g I have files with a complex name where keywords appear in different parts:

08_29_2017.gromacs_AT1_dry_sauf.1rep.step7_1.pdb
08_29_2017.gromacs_AT1_dry_Apo.1rep.step7_1.pdb
08_29_2017.gromacs_AT1_wat_apo.3rep.step7_1.pdb
08_30_2017.gromacs_AT1_wat_Na.2rep.step7_1.pdb

So only

08_30_2017.gromacs_AT1_wat_Na.2rep.step7_1.pdb

should pass to the

echo "I am sending ${name} to some place!"

at the same time if i have the files only with the one keyword e.g apo

08_29_2017.gromacs_AT1_dry_apo.1rep.step7_1.pdb
08_29_2017.gromacs_AT1_dry_apo.1rep.step7_1.pdb
08_29_2017.gromacs_AT1_wat_apo.3rep.step7_1.pdb
08_30_2017.gromacs_AT1_wat_Na.2rep.step7_1.pdb

also only the last file should be processed (but the array should consist of many 10-15 keywords including 'apo')

Aucun commentaire:

Enregistrer un commentaire