How do I remove a substring from system_profiler with a posible if then? In short, I’m writing a script that will check if a computer is a MacBook Pro or a MacBook Air and then I want to use the output as a variable. 

Using 

system_profiler SPHardwareDataType | grep “Model Name”


I can get Model Name: MacBook Pro but all I need is either “MacBook Pro” or “MacBook Air”

-oP in grep gives me an error. Another idea was to use find but I’m unsure how I’d use find if I’m not searching an actual file.
Here's a solution using awk with system_profiler :

 system_profiler SPHardwareDataType | awk -F ': ' '/Model Name/ { print $2 }'


We change the field separator to : &lt;space&gt; then search for a line with Model Name in it and print the second field. Or instead of using a pipe use process substitution to feed awk

awk -F ': ' '/Model Name/ { print $2 }' &lt; &lt;(system_profiler SPHardwareDataType)