Trying to break up a lines in a variable

I was trying to figure out a way to split along a CR in a variable.
In the code below, the result for CPU returns

CPU=`cat /proc/cpuinfo | grep -i 'model name' |awk -F ':' '{ print $2}'`

for
echo $CPU

AMD Phenom(tm) 9850 Quad-Core Processor AMD Phenom(tm) 9850 Quad-Core Processor AMD Phenom(tm) 9850 Quad-Core Processor AMD Phenom(tm) 9850 Quad-Core Processor

echo "$CPU"
AMD Phenom(tm) 9850 Quad-Core Processor
AMD Phenom(tm) 9850 Quad-Core Processor
AMD Phenom(tm) 9850 Quad-Core Processor
AMD Phenom(tm) 9850 Quad-Core Processor

what I would like to do is create a variable with

AMD Phenom(tm) 9850 Quad-Core Processor

in it so I can print it only one time.

$ cat /proc/cpuinfo | awk -F": " '/model name/{CPU=$2} END{print CPU}'

@Chubler_XL do you really need that cat?

1 Like

probably not, I was more focused on the content of the awk script, nice pickup:

awk -F": " '/model name/{CPU=$2} END{print CPU}' /proc/cpuinfo

Hmm , I'll opt for the first occurrence

awk -F": " '/model name/{print $2;exit}' /proc/cpuinfo 
1 Like
grep -i 'model name' /proc/cpuinfo | cut -d: -f2 | head -1
1 Like
sed -n '/model name/{s/.*: //p;q}' /proc/cpuinfo
1 Like

+1 for Scrutinizer solution :slight_smile: