![]() |
how to store result of wc -l command in variable?
Hi guys,
I am new to linux but trying my best. Its my first post but I give up trying to solve it. I want to store the result of wc -l as a variable so I can use it later in my script...so far unsuccessfully. I have tried this: set `echo awk '{ print $1, $6}' | wc -l` | echo $1 but it is far from working. thanks for any help! |
This is in a shell script, I take it?
Code:
MYVAR=$(echo awk '{ print $1, $6}' | wc -l) |
#!/bin/bash
MYVAR=$(wc -l ./phpf.php) echo $MYVAR please note that wc -l returns the number of lines AND the filename |
Quote:
Code:
MYVAR=$(wc -l < ./phpf.php) |
I'm completely retracting my suggestion, cause I was way off the mark!!!!
Did you try to redirect it into a file and call it back from there. I'm only new as well but i think that should work? http://www.tuxfiles.org/linuxhelp/iodirection.html e.g wc -l > /home/me/a/file Derry |
Quote:
Variables were invented to avoid having to write to disk :) |
Thanks, your reply totally made me feel better! :)
|
Quote:
|
thanks for reply. I still didn't get it to work.
var=$(wc -l) | echo $var returns nothing. I would like to omit writing the output into the file (need to repeat it 1000 times). The thing is that wc -l command is part of a longer code: grep -Fwf file1.txt file2.txt | awk '{if ($6<0.05) print $1,$6}'| var=$(wc -l) | echo $var |
because $var is empty. try this;
Code:
var="$(grep -Fwf file1.txt file2.txt | awk '{if ($6<0.05) print $1,$6}'| wc -l)" |
works! thanks a lot. I already got around it but great to know for future. Thanks for all help.
|
Quote:
|
| All times are GMT -5. The time now is 09:46 AM. |