1

Building off a question found here: How to get the offset of a partition with a bash script? in regards to using awk,bash and parted for a GPT partition

Being pretty new to scripting languages I am not sure if and how to build off the existing request.

I am looking to grab a specific partition listed by the parted command. Specifically I need the start sector of the ntfs partition for setting a offset in mount within my bash script.

root@workstation:/mnt/ewf2# parted ewf1 unit B p
Model:  (file)
Disk /mnt/ewf2/ewf1: 256060514304B
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start End Size File system  Name Flags
 1  1048576B    525336575B     524288000B   fat32  EFI system partition  boot
 2  525336576B  659554303B     134217728B          Microsoft reserved partition  msftres
 3  659554304B  256060162047B  255400607744B ntfs  Basic data partition    msftdata
Community
  • 1
  • 1
ImNotLeet
  • 381
  • 5
  • 19

3 Answers3

2

awkis your friend for this task:

$ parted ewf1 unit B p |awk '$5=="ntfs"{print $2}'

When the 5th column equals ntfs, print the second one.

mklement0
  • 382,024
  • 64
  • 607
  • 775
Juan Diego Godoy Robles
  • 14,447
  • 2
  • 38
  • 52
2

Using grep with PCRE:

parted ewf1 unit B p | grep -Po "^\s+[^ ]+\s+\K[^ ]+(?=\s.*ntfs)"

Output:

659554304B
heemayl
  • 39,294
  • 7
  • 70
  • 76
1

This will print the second field of the last line:

parted ewf1 unit B p | awk 'END { print $2  }'  # prints 659554304B

or you can search for a line that matches ntfs

parted ewf1 unit B p | awk '/ntfs/ { print $2  }'  # prints 659554304B
user1978011
  • 3,419
  • 25
  • 38