struggling with grep (even if I'm sure it is so simple)

AdvancedNoob
New Contributor III

Hi Nation,
(total noob so sorry if this is a dumb request)

context: pre imaging partition

I want to do a simple thing but cannot find online how to do it:
-I have 2 disks, both have a partition with an Apple_hfs type
-I want to grep the disk of only one by doing:

diskutil list | grep GUID_partition_scheme | grep -v ???? | awk '{print$5}'

I want to exclude

/dev/disk2 (disk image): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme +68.7 GB disk2 1: EFI EFI 209.7 MB disk2s1 2: Apple_HFS Netboot-Sierra-062018 68.4 GB disk2s2

and use Netboot-Sierra-062018 with the switch -v

any ideas?

(hope all of this makes sense)

PS: how do you pronounce grep? g-rep or grrep?

9 REPLIES 9

james_spencer
New Contributor III

diskutil list | awk '/GUID_partition_scheme/{print $5}'

you can use AWK command to search and print out the column you need

Volker
New Contributor III
PS: how do you pronounce grep? g-rep or grrep?

It's just "grep". Rhymes with "strep" and "hep".

AdvancedNoob
New Contributor III

thanks @james.spencer but GUID_partition_scheme will print 2 results in my case, and I need a command to remove one and get only one print.

athomson
New Contributor III

This should do the trick:

diskutil list | awk '/Apple_HFS Netboot-Sierra/ {print$5}'

AdvancedNoob
New Contributor III

thanks @athomson but I think I screwed up my explanation because this is not what I want. lol

pic speaks louder that my English :)
(ignore disk1 in the pic)
I need to grep disk0 to partition before imaging, my problem is GUID-partition_scheme is shown on 2 disks so when I run

cheese=$(diskutil list | grep GUID_partition_scheme | '{print$5}')

it returns 2 results so I cannot run

diskutil partitionDisk $cheese 3 GPT JHFS+ Imac 30% JHFS+ Data 40% MS-DOS BOOTCAMP R;

Hope all of this makes sense, I m all new to this.

tia

cfd81602f2ff47878151e90203908d51

m_donovan
Contributor III

It appears that you are attempting to dual boot systems. Will you always be partitioning disk0 or will it be possible to need to partition say disk2 for some reason?

AdvancedNoob
New Contributor III

@m.donovan in theory it is always disk0 but we never know, hence using variable to make sure it is always consistent

m_donovan
Contributor III

You could try:

diskutil list internal

This should only include the disk0 in your example.

AdvancedNoob
New Contributor III

@m.donovan works perfectly like I wanted! thanks