Skip to main content

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?

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



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


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


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


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.


This should do the trick:



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

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




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?


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


You could try:



diskutil list internal


This should only include the disk0 in your example.


@m.donovan works perfectly like I wanted! thanks


Reply