how to count the number of llines inside a file and put the output into a variable?
hi
i need to count the number of files and put the output into a variable. i used wc -l filename but i couldnt find an option to put the output to variable. example if the number o line is 5, i need the output of echo $x is 5. can anyone help please :) |
Well there are other issues with your command in that it includes other data than the number of lines. I will let you work out how to get rid of that, but
have a look at your favourite bash site about backticks (``) or $() features. Clue: These are synonymous but one has the advantage of readability and negates the need for escaping in some circumstances :) |
hi
it should be: x=$(cat filename | wc -l) thanks for the help :) |
Quote:
wc -l filename | awk '{print $1}' It's just another way to do it. |
All times are GMT -5. The time now is 09:11 PM. |