LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   wc -l command and playing with it (https://www.linuxquestions.org/questions/linux-newbie-8/wc-l-command-and-playing-with-it-731965/)

shoemoodoshaloo 06-10-2009 11:10 AM

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?

Tinkster 06-10-2009 11:22 AM

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

harsshal 06-10-2009 11:29 AM

Code:

echo Your line count is, `wc -l <file_name> | cut -d ' ' -f 1`

shoemoodoshaloo 06-10-2009 12:22 PM

Thanks guys.

I will read that manual.

shoemoodoshaloo 06-10-2009 12:44 PM

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.

shoemoodoshaloo 06-10-2009 12:47 PM

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.

Tinkster 06-10-2009 02:26 PM

Well do :}


Cheers,
Tink


All times are GMT -5. The time now is 06:54 PM.