Results 1 to 5 of 5

Thread: system info script

  1. #1
    Join Date
    Sep 2006
    Location
    Florida
    Beans
    187
    Distro
    Ubuntu

    Question system info script

    I'm not sure this in the right place, but I didn't see a shell scripting specific forum.

    I'm writing a system info script, and I'm having a problem with one particular part.

    I'm trying to get the systems processor using:

    Code:
    cat /proc/cpuinfo | awk '/model name/ {print $4, $5, $6, $7, $8}'
    Which returns:

    Code:
    Intel(R) Celeron(R) D CPU 3.33GHz
    It's not absolutely necessary, but I'd like to remove the (R)'s if possible - I'm picky.

    I've done some experimenting with cut and grep, but I couldn't find anything that worked.

    Does anyone have a suggestion?

    Thx
    Never let a computer know you’re in a hurry.

  2. #2
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: system info script

    I'm certain it can be done in awk, but I'm not an awk'er. You could do it with sed like this:
    Code:
    cat /proc/cpuinfo | awk '/model name/ {print $4, $5, $6, $7, $8}' | sed -e 's/.R.//g'

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: system info script

    The awk equivalent would be 'gsub' I think,

    Code:
    cat /proc/cpuinfo | awk '/model name/ {gsub(/\(R\)/,""); print $4, $5, $6, $7, $8}'
    or if you want to replace anything enclosed by parentheses such as (TM) as well as (R), you could try

    Code:
    cat /proc/cpuinfo | awk '/model name/ {gsub(/\([^)]+\)/,""); print $4, $5, $6, $7, $8}'

  4. #4
    Join Date
    Sep 2006
    Location
    Florida
    Beans
    187
    Distro
    Ubuntu

    Re: system info script

    Thank you very much for this!

    I'll have to get more in depth with awk and sed. I wasn't even aware of gsub.

    Code:
    {gsub(/\(R\)/,"")
    and
    Code:
    {gsub(/\([^)]+\)/,"")
    Are a complete mystery to me.. lol.
    Never let a computer know you’re in a hurry.

  5. #5
    Join Date
    Apr 2012
    Beans
    7,256

    Re: system info script

    The regex syntax is essentially the same whether you do the actual match in awk or sed, unfortunately yes it does look like an explosion in a punctuation factory, but basically /.../ are the regular expression delimiters (which you already know about), then

    Code:
    \(...\)
    are literal parentheses and

    Code:
    [^)]+
    means one or more characters excluding right parenthesis so

    Code:
    \([^)]+\)
    is a non-greedy way to match any non-empty sequence of characters between parentheses

Tags for this Thread

Bookmarks

Posting Permissions

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