LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-30-2009, 07:03 PM   #1
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Rep: Reputation: 0
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?
 
Old 07-30-2009, 07:17 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
cat $FILE | wc -l
Passing the content of the file as standard input, there is no file name to display.
 
Old 07-30-2009, 07:22 PM   #3
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
numlines=$(($(wc -l filename | cut -d " " -f 1 -)/2))
 
Old 07-30-2009, 07:51 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Or something like:
Code:
MIDPOINT=$(awk 'END{print NR/2}' $FILE)
 
Old 07-30-2009, 08:01 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
let MIDPOINT=`echo "wc -l < $FILE"`
 
Old 08-03-2009, 04:02 PM   #6
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks everyone.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash command to list installed libraries and version numbers newtovanilla Linux - Newbie 4 07-18-2008 05:49 PM
LXer: Keeping Command History across Multiple Sessions LXer Syndicated Linux News 1 11-07-2007 11:58 AM
keeping traffic numbers for ppp0 or eth0 interface sensovision Linux - Networking 7 03-10-2005 05:41 PM
ls command with numbers? SciYro Linux - General 2 04-17-2004 05:50 PM
Bash script: add all numbers from command output wi-Z-art Programming 2 08-06-2003 10:16 AM


All times are GMT -5. The time now is 12:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration