3

I want to extract the info from lshw output where it says:

-cpu product: ...... 

I want only the product info of this -cpu.

How can I do that with awk or sed?

2 Answers 2

2

You can filter using the utility lshw, itself:

lshw -C cpu 

That prints only the cpu part. But if you only want the product part then you need awk:

lshw -C cpu | awk '$1=="product:"{$1=""; print}' 

It searches for the string product: in the first field variable and removes that part before printing the rest of the line.

0
-2

Mr Moderator please move this as a comment to chaos’ answer, I can’t comment because I don’t have the beans ;-) I do believe such commands like lshw or lsblk should have a way to return the exact desired string without parsing the output with awk or sed or whatever, especially now that these tools are often localized and you must parse differently according to language! I have been struggling like mad with this issue.

4
  • The easy way to un-localize a command for parsing by scripts/tools is (in Bash or Bourne/POSIX-y shells) LANG=C shw -C cpu Commented Aug 19, 2023 at 20:05
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Aug 19, 2023 at 20:15
  • Anyway my request remains 100% valid because the retrieval of raw values would be less time consuming and error-prone, at least for non sed/awk experts, than having to fiddle with parsing tools. Commented Aug 20, 2023 at 12:57
  • Inflexible enforcement of arbitrary rules : you moderators won’t complain when you are replaced by bots. BTW the awk/sed stuff may become obsolete with new releases of the tool. Commented Nov 3, 2023 at 20:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.