How do I remove a substring from system_profiler with a posible if then?
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)