linux - loop multiple file with only 1st file being read -
so have works going mulitple directories within these directories takes multiple fields files , store in .txt files. there 2 loop, first 1 loops through folder second 1 loops through files. problem encounter in second loops read first file in folder , moves on next folder , ignore other files in folder.
archive=/imdata/archive inventory_archive=/imdata/a/shares/b/inventory/c ls $archive | while read p; echo "project: $p" mkdir -v $inventory_archive/$p dir=$inventory_archive/$p ls -1 $archive/$p/d001 | while read s; echo "searching session: $s ..." find $archive/$p/d001/$s -type f -iname "*.txt" | while read f; echo "file: $f" study=`/home/me/program/bin/script $f | grep -m1 "field1" | cut -d "[" -f2 | cut -d "]" -f1` echo "sid: $study" if [ ! -d "$dir/$study" ]; mkdir -v $dir/$study fi studydir=$dir/$study series=`/home/me/program/bin/script $f | grep -m1 "field2" | cut -d "[" -f2 | cut -d "]" -f1` echo "sid_2: $series" if [ ! -a "$studydir/$series.txt" ]; touch $studydir/$series.txt fi sop=`/home/me/program/bin/script $f | grep -m1 "field3" | cut -d "[" -f2 | cut -d "]" -f1` echo "sid_3: $sop" grep -qsf $sop $studydir/$series.txt || echo $sop >> $studydir/$series.txt exit 1; done; done; done;
Comments
Post a Comment