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.
If the real request is to copy the last space-separated string regardless of its length, then the best solution seems to be using
... | awk '{print $NF}'
as given by @Johnsyweb. But if this is indeed about copying a fixed number of characters from the end of a string, then there is a bash-specific solution without the need to invoke any further subprocess by piping:Please note that the space between colon and minus character is essential, as without it the full string will be delivered:
instead of using named variables, develop the practice of using the positional parameters, like this:
Try this, say if the string is stored in the variable foo.