get just the integer from wc in bash

Jordan picture Jordan · Sep 19, 2010 · Viewed 90.6k times · Source

Is there a way to get the integer that wc returns in bash?

Basically I want to write the line numbers and word counts to the screen after the file name.

output: filename linecount wordcount Here is what I have so far:

files=`ls`
for f in $files;
do
        if [ ! -d $f ] #only print out information about files !directories
        then
                # some way of getting the wc integers into shell variables and then printing them
                echo "$f $lines $ words"
        fi
done

Answer

BananaNeil picture BananaNeil · Jan 29, 2012

Most simple answer ever:

wc < filename