I am trying to create a command that works with the output to check the partition type and name. I have just discovered a solution using awk
or perhaps sfdisk
?
Here's my base output:
root@debian:/home/si# sudo sfdisk -l /dev/sda --quiet | awk '{print $0}'
Périphérique Amorçage Début Fin Secteurs Taille Id Type
/dev/sda1 * 2048 2000895 1998848 976M 83 Linux
/dev/sda2 2000896 86962175 84961280 40,5G 8e LVM Linux
Now let's filter on column $1
,$7
and $8
root@debian:/home/si# sudo sfdisk -l /dev/sda --quiet | awk '{print $1, $7, $8}'
Périphérique Id Type
/dev/sda1 83 Linux
/dev/sda2 LVM Linux
It seems there's an offset on column because LVM
value on /dev/sda2
should belong to the Type
column, so the $8
column if I'm right.
How does awk
displays the columns ? Is there any filter I miss ?
In my mind, the output columns display should be like (|
manually add)
$1 | $2 | $3 | $4 | $5 | $6 | $7 | $8
Périphérique | Amorçage | Début | Fin | Secteurs | Taille | Id | Type
/dev/sda1 |* | 2048 | 2000895 | 1998848 | 976M | 83 | Linux
/dev/sda2 | | 2000896 | 86962175 |84961280 | 40,5G | 8e | LVM Linux