Question

I have this:

echo -e "\n\n"
find /home/*/var/*/logs/ \
     -name transfer.log \
     -exec awk -v SUM=0 '$0 {SUM+=1} END {print "{} " SUM}' {} \; \
  > >( sed '/\b0\b/d' \
       | awk ' BEGIN {printf "\t\t\tTRANSFER LOG\t\t\t\t\t#OF HITS\n"}
               {printf "%-72s %-s\n", $1, $2}
             ' \
       | (read -r; printf "%s\n" "$REPLY"; sort -nr -k2)
     )
echo -e "\n\n"

When run on a machine with bash 4.1.2 always returns correctly except I get all 4 of my new lines at the top.

When run on a machine with bash 3.00.15 it gives all 4 of my new lines at the top, returns the prompt in the middle of the output, and never completes just hangs.

I would really like to fix this for both versions as we have a lot of machines running both.

Was it helpful?

Solution 2

The answer I found was to use a while read

echo -e "\n\n"; \
printf "\t\t\tTRANSFER LOG\t\t\t\t\t#OF HITS\n"; \
while read -r line; \
do echo "$line" |sed  '/\b0\b/d' | awk '{printf "%-72s %-s\n", $1, $2}'; \
done < <(find /home/*/var/*/logs/ -name transfer.log -exec awk -v SUM=0 '$0 {SUM+=1} END{print "{} " SUM}' {} \;;) \
|sort -nr -k2; \
echo -e "\n\n"

OTHER TIPS

Why make life so difficult and unintelligible? Why not simplify?

TXFRLOG=$(find /home..... transfer.log)
awk .... ${TXFRLOG}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top