I have a script that is running and uses
lspci -s 0a.00.1
This returns
0a.00.1 usb controller some text device 4dc9
I want to get those last 4 characters inline such that
lspci -s 0a.00.1 | some command to give me the last 4 characters.
I have a script that is running and uses
lspci -s 0a.00.1
This returns
0a.00.1 usb controller some text device 4dc9
I want to get those last 4 characters inline such that
lspci -s 0a.00.1 | some command to give me the last 4 characters.
Using
sed
:Output:
Try using
grep
:This will print last 4 characters of every line.
However if you'd like to have last 4 characters of the whole output, use
tail -c4
instead.I usually use
Do you really want the last four characters? It looks like you want the last "word" on the line:
This will work if the ID is 3 characters, or 5, as well.
One more way to approach this is to use
<<<
notation:How about
tail
, with the-c
switch. For example, to get the last 4 characters of "hello":Note that I used 5 (4+1) because a newline character is added by
echo
. As suggested by Brad Koch below, useecho -n
to prevent the newline character from being added.