On 25 September 2017 at 10:27, Mark Rogers mark@more-solutions.co.uk wrote:
Having read the docs I'll go for something much closer to the output generated by "sfdisk -d", massively simplifying the process for sed.
Here's what I end up with:
sudo sfdisk -d /dev/sdd | \ sed -E '/^(label(-id)?|device):/d # Remove unwanted headers ; /^$/d # Remove blank lines ; s#^/dev/[a-z0-9]+ *: *## # Remove device prefixes ; s# *= *#=#g # Remove whitespace around = signs ; s#start=[0-9]+,## # Remove start values ; $ s#size=[0-9]+,## # Remove last size value ' (Apologies for any wrapping!)
The result is: unit: sectors size=85622, type=c size=5521408, type=83 type=83
The "$" trick to apply an expression to the last line of the input only was a new one on me, as was EOL commenting within the script.