fdisk is a wonderful little utility for managing partitions. I recently had to
script a series of fdisk commands for resizing a partition and needed to extract
the start sector from the existing disk to do so. I ended up using this
awk to do the job.
This line executes
fdisk with the
-l option to list the current disks. Then
grep to find the current boot disk. Finally,
awk retrieves the
third token of the string where the token seperator is empty space.
Having the start sector I was able to script the fdisk sequence by piping the necessary sequence of resize commands into fdisk.