ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
There's no need to use grep or anything else when awk can do everything itself. Awk is not just a column-printing program, it's a rich and complex scripting language. It can do just about everything grep and sed can do, and even has a built-in mathematical engine on a near-par with bc.
In this case, you just have to increment the value of an awk variable for each line it finds, then print the final value at the end.
But also, on my system I came up with a "No Module Installed" entry when I ran dmidecode, so you'll should check that the string is appropriate too.
Ah, Thanks grail. I originally posted a simpler version, then decided I should expand the regex to make the test more stringent. I tested it in the shell with the full $2 ~ /^[0-9]+$/ , but I forgot to add that part when I edited my post. Sorry.