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:

grep -i processor /proc/cpuinfo | awk '{print $1$2,$3}'

yields:

processor: 0
processor: 1
processor: 2
processor: 3

The second command:

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

yields:

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:

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.

[/SIZE]

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

I'll leave the removal of "model name :" to you.

1 Like

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

Thanks very much for your help.

Regards,
jamarsh

Another way, perhaps in other circumstances, could be to use named pipes. For instance:

$ 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

1 Like

I shall review this option as well. I have another area to look into - named pipes.
Thanks so much
jamarsh