Linux, how to parsing for pci express NVMe?

Issue

I’m working on bash script getting the pci nvme address for hot reset.

I want to parsing for pci express nvme ADDRESS (i.e /sys/devices/pci0000:00/0000:00:01.2/0000:01:00.2/0000:02:00.0/0000:03:00.0/nvme/nvme0

how can i do this?

I want to parse the address value before nvme.

Solution

You can use cut with / as the delimiter.

addr='/sys/devices/pci0000:00/0000:00:01.2/0000:01:00.2/0000:02:00.0/0000:03:00.0/nvme/nvme0'
nvme=$(cut -d/ -f8 <<<"$addr")
echo "$nvme"

Answered By – Barmar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published