0

I want to find the file with the biggest number of words in a directory so I tried to use just the second line from the output of this command :

wc * -w | sort -nr

In fact I know that it will work if i saved the output to a file and used the command sed like this :

wc * -w | sort -nr >> file
sed -n "2p" file

but this is not what I want , I need to do it via the output of the command directly

I tried with a script shell like :

for i in `wc * -w | sort -nr`
do
if test $i -eq 2 then
echo "$i"
fi
done

but it was not what I expected Thank you in advance.

Hamzaoui
  • 3
  • 1

1 Answers1

0
find -type f -exec wc -w {} + | sort -nr | awk NR==2
  • use find instead, wildcard will find folders as well
  • pipe to awk
Zombo
  • 1
  • 62
  • 391
  • 407