2

I am new at writing scripts. So I am hoping this is simple. The script I am writing is used to gather system information and save it as an html file.

When I run:

sudo lshw -short

it list all of the hardware on a system.

When I run:

sudo lshw -short | grep processor

it returns (the dots represent spaces)

/0/4                        ...........................................processor................................................   AMD FX(tm)-6100 Six-Core Processor"

My question is how to I remove everything in front of processor. Or how do I only display what is after "processor". I tried several other options for grep and tried to find an awk command to work, but I have failed in my attempts.

If more information is need let me know.

5

In versions of grep that support the PCRE (Perl Compatible Regular Expression) extension, you can do

sudo lshw -short | grep -Po 'processor\K.*'

The -o says to only print the matching text, and \K modifier causes anything to its left in the matching text to be excluded from the result.

If you want to also remove any white space following the literal text processor, you can do

sudo lshw -short | grep -Po 'processor\s*\K.*'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.