-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.

4 Answers4

3

Tryt to do it this way:

inxi -Gx | sed -n 's/.*Device-.*: \(.*\) vendor.*/\1/p'
  • 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
  • 808
  • 4
  • 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,384