On 2015-01-20, Kenny McCormack <
gaz...@shell.xmission.com> wrote:
> In article <
932d0b39-eaa1-443f...@googlegroups.com>,
> <
cla...@gmail.com> wrote:
>>Hi
>>
>>I have 5 lines like below, which I like to join into one.
>>
>>top - 13:49:55 up 402 days, 22:38, 4 users, load average: 1.69, 1.58, 1.79
>>Tasks: 397 total, 4 running, 393 sleeping, 0 stopped, 0 zombie
>>Cpu(s): 4.0%us, 0.8%sy, 0.0%ni, 95.0%id, 0.2%wa, 0.0%hi, 0.1%si, 0.0%st
>>Mem: 15950M total, 15155M used, 795M free, 77M buffers
>>Swap: 2055M total, 101M used, 1953M free, 10928M cached
>>
>>the joined output should look like this:
>>top - 13:49:55 up 402 days, 22:38, 4 users, load average: 1.69, 1.58, 1.79
>>Tasks: : 397 total, 4 running, 393 sleeping, 0 stopped, 0 zombie Cpu(s):
>>4.0%us, 0.8%sy, 0.0%ni, 95.0%id, 0.2%wa, 0.0%hi, 0.1%si, 0.0%st Mem:
>>15950M total, 15155M used, 795M free, 77M buffers Swap: 2055M
>>total, 101M used, 1953M free, 10928M cached.
>>(join line before Tasks, Cpu(s), Mem and Swap)
>>
>>But how do I do this using the sed command?
>
> Don't use sed. As Kaz notes, sed is both off-topic and almost never the
> right tool.
Moreover, it should almost never be the right tool in the sense that it is
available, whereas awk isn't.
Anything that calls itself POSIX, and even things that call
themselves pre-POSIX Unixes, will almost certainly not have one without the
other.
However, in a situation where sed has to be used because awk isn't available
(because, for instance, someone hacked down some *nix distro to fit into a
small EEPROM memory or whatever, and there was no room for awk),
comp.lang.awk would then obviously be the right newsgroup to ask.
It's a Usenet rule! If you can't use X because it is not available, then you
must ask for a solution specifically in comp.lang.X.
This is topical because your solution is being developed in the specific
emotional context of *wishing* that you had X, and you want to reduce your
distress by sharing your feeling with other X programmers. Secondly, the
solution will use Y as if it were X, using X-like idioms in Y even if they are
inappropriate! Lastly, the archived discussion might be of value to any
X programmer who lands in the same predicament.