Merge output of 2 commands into variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge output of 2 commands into variable
# 1  
Old 10-14-2012
Merge output of 2 commands into variable

I am extracting two pieces of information from the following file: /proc/cpuinfo, that I need to merge into one report.

The first command:
Code:
grep -i processor /proc/cpuinfo | awk '{print $1$2,$3}'

yields:
Code:
processor: 0
processor: 1
processor: 2
processor: 3



The second command:
Code:
grep -i "model name" /proc/cpuinfo | awk '{print $4, $5, $6, $7, " ", $8, $9, $10, $11}'

yields:

Code:
Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz

I want a report that looks like this:
Code:
processor: 0 Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
processor: 1 Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
processor: 2 Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz
processor: 3 Intel(R) Core(TM) i3 CPU   M 370 @ 2.40GHz


I am working from a live CD, so I cannot use files. I figure this can be done using a variable or array. I'm still learning Bash, so a point in the right direction would be most helpful.



Last edited by Scrutinizer; 10-15-2012 at 02:29 AM.. Reason: code tags
# 2  
Old 10-14-2012

Code:
awk '/^processor/ { processor = $0 }
/^model name/ { print processor, $0 }
' /proc/cpuinfo

I'll leave the removal of "model name :" to you.
This User Gave Thanks to cfajohnson For This Post:
# 3  
Old 10-15-2012
Merge output of 2 commands into variable

I got it! I can see it is well worth spending some time with awk.

Thanks very much for your help.

Regards,
jamarsh
# 4  
Old 10-15-2012
Another way, perhaps in other circumstances, could be to use named pipes. For instance:
Code:
$ mkfifo cmd1 cmd2
$ exec 2>/dev/null; echo -e "this\nthat" >cmd1 & echo -e "first\nsecond" >cmd2 & paste cmd1 cmd2; rm cmd1 cmd2; exec 2>/dev/tty
this	first
that	second
$

--
Bye
This User Gave Thanks to Lem For This Post:
# 5  
Old 10-15-2012
I shall review this option as well. I have another area to look into - named pipes.
Thanks so much
jamarsh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Merge two text files by two fields and mixed output

Hello, I'm back again looking for your precious help- This time I need to merge two text files with matching two fields, output only common records with mixed output. Let's look at the example: FILE1 56153;AAA0708;3;TEST1TEST1; 89014;BBB0708;3;TEST2TEST2; 89014;BBB0708;4;TEST3TEST3; ... (7 Replies)
Discussion started by: emare
7 Replies

2. Shell Programming and Scripting

E-mail Output Merge Lines for Some Text..

Hi all. This is the content of the text file used for the e-mail: TM ICP-EDW BILLING REGISTER USAGE BREAKDOWN_01062014.csv TM_ICP_EDWH_FICL_13062014.TXT TM_ICP_EDWH_FICL_16062014.TXT TM_ICP_EDW_Detailed Payment Journal Report_13062014.txt TM_ICP_EDW_Detailed Payment Journal... (9 Replies)
Discussion started by: aimy
9 Replies

3. UNIX for Advanced & Expert Users

How to merge two commands

I have input like Unload: 2610000 225 2198 374 315 420 1149 57 2611 595 662 374 820 130 2938 486 2483 397 760 using these values, i need to divide first number with second number, means 225/2198, and using the value i'm trying to sort it. After sort i need first and "Unload" values,... (2 Replies)
Discussion started by: arivu198314
2 Replies

4. Emergency UNIX and Linux Support

Merge Static and dynamic parts in variable declaration

Dear Unix experts Moved from "Shell Programming and Scripting " I want to define a variable which contains dynmic and static part, daynamic part is the first field. Sample of data dddd aaaa sssss 12345 ssss 2323 234234 4242 dddd 3223 34234 54353 ssss 24234 3434 42342 dddd rwrw 423423... (2 Replies)
Discussion started by: yahyaaa
2 Replies

5. Shell Programming and Scripting

Merge Static and dynamic parts in variable declaration

Dear Unix experts I want to define a variable which contains dynmic and static part, daynamic part is the first field. Sample of data dddd aaaa sssss 12345 ssss 2323 234234 4242 dddd 3223 34234 54353 ssss 24234 3434 42342 dddd rwrw 423423 werwer nawk 'BEGIN {FS=" "}{... (4 Replies)
Discussion started by: yahyaaa
4 Replies

6. UNIX for Dummies Questions & Answers

awk simple commands merge

Is there nice awk code for merging the following commands and do the last task? input1 ab100 xxx 100 blahblah + 1000 ab100 yyy 90 blahblah + 1000 ef390 ggg 200 blahblah - 2000 ef390 aaa 100 blahblah - 2000 df888 ttt 300 ... (5 Replies)
Discussion started by: ruby_sgp
5 Replies

7. Shell Programming and Scripting

Merge all commands into one

how can i merge follwoing process to one... tail +5 rawdata_AAA_1.txt_$$ | grep -v "^$" >> rawdata_AAA_2.txt_$$ For discarding first 5 rows and deleting null rows awk '!/^ /{if(a) print a; a=$0}/^ /{print a}' rawdata_AAA_2.txt >> rawdata_AAA_3.txt For merging record if it split into 2 rows... (8 Replies)
Discussion started by: Amit.Sagpariya
8 Replies

8. Shell Programming and Scripting

Merge lines in a file with Awk - incorrect output

Hi, I would like: FastEthernet0/0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 output errors, 0 collisions, 0 interface resets Serial1/0:0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort 0... (14 Replies)
Discussion started by: mv652
14 Replies

9. Shell Programming and Scripting

how to merge two variable in one variable with space between them?

Dear all I had two separate variable. Now i want to make them merge into one new variable with space between them. Kindly suggest me. var1=dec 15 var2=10 i want var3=dec 15 10 My main aim is as below: op of date command: >date >Sat Dec 15 10:17:35 IST 2007 i want only Dec... (2 Replies)
Discussion started by: jaydeep_sadaria
2 Replies

10. Shell Programming and Scripting

AWK Merge Fields for Print Output

I've got a file with each record on a separate line and each record contains 34 fields separated by a colon and i'm trying to re-arrange the order of the fields and merge together certain fields separated by a slash (like field7/field28). I tried using an awk print statement like awk -F: 'BEGIN... (5 Replies)
Discussion started by: RacerX
5 Replies
Login or Register to Ask a Question