0

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.

menders65
  • 43
  • 8
  • `echo -e "\n\n"` cause new line right? – Jayesh Bhoi Feb 14 '14 at 08:07
  • You might want to try simplifying `find ... > >( sed ... | awk ... | ( ... ) )` to `find ... | sed ... | awk ... | ( ... )`. (I don't know if that's the problem, but process substitution involves some trickinesses on Bash's part, so it seems plausible.) – ruakh Feb 14 '14 at 08:25
  • yes @JKB but they are all at the top of the output – menders65 Feb 14 '14 at 08:26
  • @menders65 `bash 4.1.2 always returns correctly but I get all 4 of my new lines at the` you stated this that's why i stated it:) if it require then keep it. – Jayesh Bhoi Feb 14 '14 at 08:34

2 Answers2

0

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

TXFRLOG=$(find /home..... transfer.log)
awk .... ${TXFRLOG}
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

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"
menders65
  • 43
  • 8