Trying to break up a lines in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to break up a lines in a variable
# 1  
Old 10-13-2010
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.
# 2  
Old 10-13-2010
Code:
$ cat /proc/cpuinfo | awk -F": " '/model name/{CPU=$2} END{print CPU}'

# 3  
Old 10-13-2010
@Chubler_XL do you really need that cat?
This User Gave Thanks to danmero For This Post:
# 4  
Old 10-13-2010
probably not, I was more focused on the content of the awk script, nice pickup:

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

# 5  
Old 10-13-2010
Hmm , I'll opt for the first occurrence
Code:
awk -F": " '/model name/{print $2;exit}' /proc/cpuinfo


Last edited by danmero; 10-13-2010 at 09:15 PM.. Reason: Update, fix error
This User Gave Thanks to danmero For This Post:
# 6  
Old 10-14-2010
Code:
grep -i 'model name' /proc/cpuinfo | cut -d: -f2 | head -1

This User Gave Thanks to frans For This Post:
# 7  
Old 10-14-2010
Code:
sed -n '/model name/{s/.*: //p;q}' /proc/cpuinfo


Last edited by Scrutinizer; 10-14-2010 at 03:45 AM..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break one long string into multiple fixed length lines

This is actually a KSH under Unix System Services (Z/OS), but hoping I can get a standard AIX/KSH solution to work... I have a very large, single line file in Windows, that we download via FTP, with the "SITE WRAP" option, into a Z/OS file with an LRECL of 200. This essentially breaks the single... (4 Replies)
Discussion started by: bubbawuzhere
4 Replies

2. Shell Programming and Scripting

Break line content into multiple lines using delimiter

I need to break the line after every 3rd semi colon(;) using Unix shell scripting Input.txt ABC;DEF;JHY;LKU;QWE;BVF;RGHY; Output.txt ABC;DEF;JHY; LKU;QWE;BVF; RGHY; (1 Reply)
Discussion started by: meet_calramz
1 Replies

3. Shell Programming and Scripting

Break lines that appear together

Hello to all May you help me with a sed or awk script to fix the text below please. I have a file where all lines should have 67 characters but from time to time 2 lines appear together like below. * First column always has 15 characters * Second column always has 32 characters * 3rd,... (5 Replies)
Discussion started by: Ophiuchus
5 Replies

4. Shell Programming and Scripting

Enumerate lines until each line break using awk

Hi, I have the following data: This this DT 0.99955 0 4 is be VBZ 1 5 7 sentence sentence NN 0.916667 8 16 one one NN 0.545078 17 20 . . Fp 1 20 21 This this DT 0.99955 22 26 is be VBZ 1 27 29 the the DT 1 30 33 second 2 JJ 0.930556 34 40 sentence sentence NN 0.916667 41 49... (1 Reply)
Discussion started by: owwow14
1 Replies

5. Shell Programming and Scripting

Trying to take a string and break each letter into a separate variable

I am trying to make a script that takes a word and each letter up and turns it into a separate variable. My code currently does not work but I feel I just need to tweak one thing that I am unsure of. (ex: if forum was typed in letter1=f; letter2=o; letter3=r;...) Thank you count=1; ... (7 Replies)
Discussion started by: crimputt
7 Replies

6. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

7. Shell Programming and Scripting

Awk to Break lines to multiple lines.

Input File: nawk -F "|" '{ for(i=1;i<=NF;i++) { if (i == 2) {gsub(",","#",$i);z=split($i,a,"")} else if (i == 3) {gsub(",","#",$i);z=split($i,b,"")} } if(z > 0) for(i=1;i<=z;i++) print $1,a,"Test"; if(w > 0) for(j=1;j<=w;j++) ... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

9. Shell Programming and Scripting

join lines on line break in files

i had a file where lines appear to be broken when they shouldn't eg Line 1. kerl abc sdskd sdsjkdlsd sdsdksd \ Line 2. ksdkks sdnjs djsdjsd i can do a shift join to combine the lines but i there are plenty of files with this issue Line 1. kerl abc sdskd sdsjkdlsd sdsdksd ksdkks sdnjs... (6 Replies)
Discussion started by: mad_man12
6 Replies

10. Shell Programming and Scripting

Break one line to many lines using awk

Break one line to many lines using awk The below code works but i want to implement without combining field 2 and 3 and then splitting i would like to do this in one command instead of writing multiple commands and creating multiple lines. nawk -F"|" '{print $1,$2SUBSEP$3}' OFS="|" file >... (16 Replies)
Discussion started by: pinnacle
16 Replies
Login or Register to Ask a Question