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?

chaos
  • 1,505
  • 1
  • 15
  • 21
UnixUser
  • 43
  • 2

2 Answers2

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.

chaos
  • 1,505
  • 1
  • 15
  • 21
-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.

  • 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` – DouglasDD Aug 19 '23 at 20:05
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://serverfault.com/help/whats-reputation) you will be able to [comment on any post](https://serverfault.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/562257) – DouglasDD Aug 19 '23 at 20:15
  • I routinely use this but it did not work last time. In any case was it necessary to rebuke me when I used the only way I had to interact with this website? Couldn’t you just put my input as a comment and give yours? I allowed you to add value to this answer by asking my question, and all you do is criticize. Bye-bye guys, farewell. – Alexandre Oberlin Aug 20 '23 at 11:16
  • 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. – Alexandre Oberlin Aug 20 '23 at 12:57