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 06-10-2009, 12:10 PM   #1
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Rep: Reputation: 0
wc -l command and playing with it


Hey everyone,

I program which at one point reads the lines in a data file using the command:

wc -l file_name

With output like:

10000 file_name

In the same program, I would like the program to recognize the line count, in this example, 10000, and print to the screen:

"Your line count is, 10000".

Is this possible in a relatively simple manner? First the program would have to identify the 10000 portion from the 10000 file_name, and then store it. Any ideas?
 
Old 06-10-2009, 12:22 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
echo "Your line count is: $( wc -l < filename )"
How to store strings in variables ... please
look at the bash manual, or the bash how-to
on www.tldp.org

Cheers,
Tink

Last edited by Tinkster; 06-10-2009 at 12:24 PM.
 
Old 06-10-2009, 12:29 PM   #3
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Rep: Reputation: 15
Code:
echo Your line count is, `wc -l <file_name> | cut -d ' ' -f 1`
 
Old 06-10-2009, 01:22 PM   #4
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Thanks guys.

I will read that manual.
 
Old 06-10-2009, 01:44 PM   #5
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
In checking some literature, I'm still not sure exactly what it's called that I am trying to do. Sorry, I'm not very familiar with the terminology yet.

As you recommended, this works:

Code:
echo "Your line count is: $( wc -l < filename )"
But now I want to store that number, say in a parameter called $linecount.

Later in the code, I will call on $linecount.

Can this be done? The closest thing I can find in guides it the

echo "statement"
read

Which seems to only be useful if the user is going to input the variable.
 
Old 06-10-2009, 01:47 PM   #6
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Nevermind. I didn't realize how easy it was and how nonsensical my followup question was.

I didn't realize I could just declare the variable with that command:

variable=$( wc -l < $RAWTAGFILEDIR/$OUTDIR/$FILTEREDRAWTAGFILE )

Very good to know, thanks guys.
 
Old 06-10-2009, 03:26 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Well do :}


Cheers,
Tink
 
  


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
Playing and looping audio cds from command line barker1977 Linux - Software 5 08-31-2008 07:02 PM
LXer: CLI Magic: Playing music from the command line with mp3blaster LXer Syndicated Linux News 0 03-28-2006 04:09 PM
Totem playing off of network, Xine playing local iammike Ubuntu 0 04-30-2005 12:43 PM
No sound when playing audio files on Fedora using command line players k_wjss Linux - Newbie 0 10-01-2004 02:32 AM
command line way of playing .mp3? purpleburple Linux - General 4 10-14-2002 01:27 PM


All times are GMT -5. The time now is 10:11 AM.

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