-1

I need to cut line in specific moment, I want to display GPU name, but only name, nothing else.

inxi -Gx | grep Device showing:

Device-2: NVIDIA GK107GLM [Quadro K1100M] vendor: Dell driver: nouveau

I want it to show something like this

NVIDIA GK107GLM [Quadro K1100M]

How to cut this to show only name? Is there a way to print range, in this case from word Device to word vendor.

  • 1
    Please [edit] your question and show the example output of `inxi -Gx | grep Device` and the expected output, [formatted as code](https://stackoverflow.com/editing-help#code). This question is about shell programming / text processing and not specifically related to Ubuntu, so it might better fit on https://stackoverflow.com/ – Bodo Jul 23 '21 at 07:45
  • Not working for me – pLumo Jul 23 '21 at 08:17
  • Thanks for your update, however, please check also: "*[...] and the expected output, [formatted as code](https://stackoverflow.com/editing-help#code).*" – pLumo Jul 23 '21 at 08:22
  • It gives output: Graphics: Device-1 Intel 4th Gen Core Processor Integrated Graphics driver: i915 – Grzegorz Michalak Jul 23 '21 at 10:10

4 Answers4

3

Tryt to do it this way:

inxi -Gx | sed -n 's/.*Device-.*: \(.*\) vendor.*/\1/p'
Apomelitos
  • 116
  • 5
  • 1
    Yes, thats it! Thank you very much. Can you describe how this works? This command – Grzegorz Michalak Jul 23 '21 at 10:53
  • 1
    Sure. 1. -n param suppresses automatic printing of pattern space(no auto output from sed command) 2. sed is looking for this pattern `.*Device-.*: \(.*\) vendor.*` 3. `/\1/` - sed replaces all the matched line to the first match group (a part of pattern in brackets `(.*\)`) 4. `/p` param in the end prints the current pattern space( print matched lines) – Apomelitos Jul 23 '21 at 11:35
0

Something like:

D=$(inxi -Gx | grep Device)

if [[ $D =~ ^Device-2:([[:print:]]*)vendor:([[:print:]]*)driver:([[:print:]]*)$ ]]
then
  echo "Found Device: ${BASH_REMATCH[1]}"
else
  echo "Did not find device"
fi
Wayne Vosberg
  • 748
  • 3
  • 5
0
inxi -Gx | grep -oi nv.*]
inxi -Gx | awk '/Device/{print $2,$3,$4,$5}'
HatLess
  • 115
  • 4
0

inxi -Gx | grep Device | cut -d ':' -f 2 | sed 's/ vendor//'

This cuts the output into fields using ":" as a delimiter, then it gives you the second field. Use sed then to strip the specific word off the end.

If you know the length then you can cut a range using cut, see man cut for details.

pbhj
  • 3,152
  • 21
  • 38