ImNotLeet
ImNotLeet

Reputation: 391

Offset of a specific listed partition

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

Upvotes: 1

Views: 502

Answers (3)

Juan Diego Godoy Robles
Juan Diego Godoy Robles

Reputation: 14955

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.

Upvotes: 2

heemayl
heemayl

Reputation: 42037

Using grep with PCRE:

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

Output:

659554304B

Upvotes: 2

user1978011
user1978011

Reputation: 3589

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

Upvotes: 1

Related Questions