#!/bin/bash
ARCHIVE="$PWD"
#ARCHIVE="/home/kschmidt/public_html/Files/DrMathArchive"
NUMBERofDIRS=0
TEST=""
for dir in `ls -l ${ARCHIVE}| egrep '^d' | awk '{print $9}'`;
do
for EACHFILE in `find ${ARCHIVE}/${dir} -type f -name "prob*" `
do
TEMP3="${EACHFILE##*/}"
TEMP2="${TEMP3%%_*}"
echo "${TEMP2}" >> output.txt
(find ${ARCHIVE}/${dir} -type f -name "${TEMP2}*" | awk -F/ '{print $NF}' \
| wc -l)
done
done
I am trying to put the list of files echoed with TEMP2 followed by the number got from the find command. I can list both separately, but I can do one next to another in the form of two columns.
Also, you don't need awk | sed | grep | kitchen | sink to find only directories.
Also, you don't have to reopen the same file 10,000 times to write 10,000 lines, you can redirect the output of an entire loop.
ls "$ARCHIVE" | while read DIR
do
[ -d "$DIR" ] || continue # Ignore non-directories
for EACHFILE in "$ARCHIVE/$DIR/prob"*
do
TEMP3="${EACHFILE##*/}"
TEMP2="${TEMP3%%_*}"
# Use globbing to count files.
set -- "$ARCHIVE/$DIR/${TEMP2}"*
echo "$TEMP2" "$#"
done
done > outputfile
cd $ARCHIVE
#for dir in `ls -l ${ARCHIVE}| egrep '^d' | awk '{print $9}'`
for dir in *
do
[ ! -d "$dir" ] && continue
echo $dir
done
If you need only look subdir, not subtree then
saved=$PWD
> $saved/output.txt
cd $ARCHIVE
for dir in *
do
[ ! -d "$dir" ] && continue
cd $dir
cnt=0
for file in prob*
do
[ "$file" = "prob*" ] && continue # not exists any probe*
echo "$dir/$file" >> $saved/output.txt
((cnt+=1))
done
echo "$cnt"
cd $ARCHIVE
done
I wasn't sure what do you really need to do. But maybe previous give some ideas.