LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   wc -l command, only keeping the numbers (https://www.linuxquestions.org/questions/linux-newbie-8/wc-l-command-only-keeping-the-numbers-744018/)

shoemoodoshaloo 07-30-2009 06:03 PM

wc -l command, only keeping the numbers
 
Hey everyone,

I am writing a small script which has to take the number of lines in a file, divide it by two, and store it as a variable:

I first tried to store the number of lines in a file with:

Code:

let MIDPOINT=`echo "wc -l $FILE"`
but realized that this will try to store the number of lines and the file name. How can I change this to store only the number of lines?

colucix 07-30-2009 06:17 PM

Code:

cat $FILE | wc -l
Passing the content of the file as standard input, there is no file name to display. ;)

jay73 07-30-2009 06:22 PM

numlines=$(($(wc -l filename | cut -d " " -f 1 -)/2))

colucix 07-30-2009 06:51 PM

Or something like:
Code:

MIDPOINT=$(awk 'END{print NR/2}' $FILE)

Tinkster 07-30-2009 07:01 PM

Code:

let MIDPOINT=`echo "wc -l < $FILE"`

shoemoodoshaloo 08-03-2009 03:02 PM

Thanks everyone.


All times are GMT -5. The time now is 05:17 AM.