Find the answer to your Linux question:
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 ...
  1. #1
    Linux 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!!!!!!!!!

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    You could use a sed:

    Code:
    print "\nProcessor : ";
    system ("cat /proc/cpuinfo | grep \"model name\" | sed s/model name ://");
    Linux User #453176

  3. #3
    Linux 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

  4. #4
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Sorry, I forgot the quotes:

    Code:
    print "\nProcessor : ";
    system ("cat /proc/cpuinfo | grep \"model name\" | sed 's/model name ://'");
    Linux User #453176

  5. #5
    Linux 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+

  6. #6
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    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

  7. #7
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    You can do all this with one sed command:

    Code:
    sed -n '/model name/s/.*: \(.*\)/\nProcessor : /\1/p' /proc/cpuinfo
    Regards

  8. #8
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by goude View Post
    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!!!!!!!!!
    if you are using Perl, then use Perl..... One way , (or you can use external Perl modules like Linux::Cpuinfo )
    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);
    output:
    Code:
    # ./test.pl
    Processor :  Intel(R) Core(TM)2 CPU         T5500  @ 1.66GHz
    Processor :  Intel(R) Core(TM)2 CPU         T5500  @ 1.66GHz

  9. #9
    Linux User
    Join Date
    Jul 2007
    Location
    Greece
    Posts
    277
    Thank you all for your replies.

    Problem solved

    THANK YOU VERY MUCH!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...