正则表达式列出blkid标签

时间:2017-01-12 06:31:06

标签: regex blkid

Apols但确定有人可以提供这个正则表达式只是不与我一起计算。

如果我想要匹配LABEL的UUID部分=" Usb3Ext"

,那么说如果我从blkid得到这个输出
/dev/sda1: UUID="f2134523-0628-f8bd-359d-4f19069e2b6e" UUID_SUB="3e97c008-8038-bca2-5073-bfedb2e24ee8" LABEL="portal:1" TYPE="linux_raid_member" PARTUUID="e52e2353-01"
/dev/sda2: UUID="9780d08b-9074-bf5f-89ab-ed685fac0dc9" UUID_SUB="ab859874-a289-9ae4-79d3-684617fe38fe" LABEL="portal:3" TYPE="linux_raid_member" PARTUUID="e52e2353-02"
/dev/sdc1: UUID="f2134523-0628-f8bd-359d-4f19069e2b6e" UUID_SUB="d6abfac6-856a-9672-9232-5c98bb91c720" LABEL="portal:1" TYPE="linux_raid_member" PARTUUID="f69e85ae-01"
/dev/sdc2: UUID="9780d08b-9074-bf5f-89ab-ed685fac0dc9" UUID_SUB="6d9a1d85-c9a1-3e15-50fc-a5e1e80f8072" LABEL="portal:3" TYPE="linux_raid_member" PARTUUID="f69e85ae-02"
/dev/sdf1: UUID="27886912-a152-6259-d9f1-2c8d14405533" UUID_SUB="2edc6f6c-edeb-f831-e637-53b41791b49e" LABEL="portal:0" TYPE="linux_raid_member" PARTUUID="000a6200-01"
/dev/sdf2: UUID="8b9b8b6d-4031-b112-2860-8e723892199e" UUID_SUB="5cea45a4-5cf2-2c84-d206-241f9a05f1f7" LABEL="portal:2" TYPE="linux_raid_member" PARTUUID="000a6200-02"
/dev/sde1: UUID="27886912-a152-6259-d9f1-2c8d14405533" UUID_SUB="1d1eda6c-2f9b-c3b1-b69e-736502073e1d" LABEL="portal:0" TYPE="linux_raid_member" PARTUUID="00058248-01"
/dev/sde2: UUID="8b9b8b6d-4031-b112-2860-8e723892199e" UUID_SUB="f8a3e9b2-bde9-cd40-fc7e-222d1c212359" LABEL="portal:2" TYPE="linux_raid_member" PARTUUID="00058248-02"
/dev/sdd1: UUID="f2134523-0628-f8bd-359d-4f19069e2b6e" UUID_SUB="ba674983-f388-6831-9caa-846c9c217caf" LABEL="portal:1" TYPE="linux_raid_member" PARTUUID="9206526c-01"
/dev/sdd2: UUID="9780d08b-9074-bf5f-89ab-ed685fac0dc9" UUID_SUB="15862e61-323f-7a35-6323-7ae6b2f88335" LABEL="portal:3" TYPE="linux_raid_member" PARTUUID="9206526c-02"
/dev/sdb1: UUID="f2134523-0628-f8bd-359d-4f19069e2b6e" UUID_SUB="2713996c-c9b1-b1c7-d21c-c3ff7e8a6628" LABEL="portal:1" TYPE="linux_raid_member" PARTUUID="e52e2345-01"
/dev/sdb2: UUID="9780d08b-9074-bf5f-89ab-ed685fac0dc9" UUID_SUB="1ddbfcd6-118c-66b7-7f61-714d6c82f578" LABEL="portal:3" TYPE="linux_raid_member" PARTUUID="e52e2345-02"
/dev/md0: UUID="9eee0c53-b920-4a2e-8d50-076ad950ed16" TYPE="swap"
/dev/md2: UUID="7e76c28f-255a-4632-a61d-366d20e69cbb" TYPE="ext4"
/dev/md1: UUID="b6ba4ca4-2600-4126-80d5-e31d42a9627d" TYPE="swap"
/dev/md3: UUID="b7e77394-eedf-4759-889b-fd0883a3255a" TYPE="ext4"
/dev/sdg1: SEC_TYPE="msdos" LABEL="CLONEZILLA" UUID="9694-42D7" TYPE="vfat" PARTUUID="2d4d327f-01"
/dev/sdh1: LABEL="Usb3Ext" UUID="4606033506032611" TYPE="ntfs" PARTUUID="a4022ef6-01"

非常感谢

2 个答案:

答案 0 :(得分:0)

您可以像这样使用awk

blkid | awk '/LABEL="Usb3Ext"/{i=gensub(/.* UUID="(.*)".*/, "\\1", "g");print i}'

sed

blkid | sed '/LABEL="WINRE_DRV"/!d;s/.* UUID="\(.*\)".*/\1/'

最好使用lsblk

lsblk -no LABEL,UUID | awk '$1 == "Usb3Ext" {print $2}'

答案 1 :(得分:0)

不太优雅,但它有效(不过UUID出现的地方):

blkid | awk -F'UUID = \“''{print $ 2}'| awk -F”\“”'{print $ 1}'