Results 1 to 9 of 9
Hello everyone,
I have written a small perl program that displays all the information of my computer.
One of these info is the speed processor.
To print that information I ...
- 02-01-2008 #1Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
using the grep command
Hello everyone,
I have written a small perl program that displays all the information of my computer.
One of these info is the speed processor.
To print that information I did:
print "\nProcessor : ";
system ("cat /proc/cpuinfo | grep \"model name\"");
Now this prints out the following:
Processor : model name : AMD Athlon(tm) 64 Processor 3800+
Is there a way to get rid of "model name"? So, that it prints out:
Processor : AMD Athlon(tm) 64 Processor 3800+
Doesn anyone have any suggestions please?
Thank you!!!!!!!!!
- 02-01-2008 #2
You could use a sed:
Code:print "\nProcessor : "; system ("cat /proc/cpuinfo | grep \"model name\" | sed s/model name ://");Linux User #453176
- 02-01-2008 #3Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Thank you for your reply Kieren,
This is what I get using sed. By the way, very useful command, didn't know about it.
Processor : sed: -e expression #1, char 7: unterminated `s' command
- 02-01-2008 #4
Sorry, I forgot the quotes:
Code:print "\nProcessor : "; system ("cat /proc/cpuinfo | grep \"model name\" | sed 's/model name ://'");Linux User #453176
- 02-01-2008 #5Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Didn't make any difference.

With the quotes, it prints out
Processor : model name : AMD Athlon(tm) 64 Processor 3800+
- 02-01-2008 #6
There is a tab hidden in /proc/cpuinfo. Use the following instead:
Code:print "\nProcessor : "; system ("cat /proc/cpuinfo | grep "model name" | sed 's/model name\t: //'");Linux User #453176
- 02-01-2008 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
You can do all this with one sed command:
RegardsCode:sed -n '/model name/s/.*: \(.*\)/\nProcessor : /\1/p' /proc/cpuinfo
- 02-01-2008 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you are using Perl, then use Perl..... One way , (or you can use external Perl modules like Linux::Cpuinfo )
output:Code:open(CPU, "<", "/proc/cpuinfo") or die "cannot open file"; while (<CPU>) { if ( m/model name/ ) { my ($one,$two) = split (/:/,$_); print "Processor : " . $two; } } close(CPU);
Code:# ./test.pl Processor : Intel(R) Core(TM)2 CPU T5500 @ 1.66GHz Processor : Intel(R) Core(TM)2 CPU T5500 @ 1.66GHz
- 02-01-2008 #9Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Thank you all for your replies.
Problem solved
THANK YOU VERY MUCH!!!


Reply With Quote
