Discussion:
How to combine lines of output, 3 at a time?
'Van Handel' djvh2@comcast.net [sed-users]
2017-05-23 00:16:30 UTC
Permalink
Hello. This is on Linux. I have a command that returns many

attributes for each set top box on a headend, but I only need the

MacAddr, HubId, and Model.



To get that info, I pipe the output to grep & sed like this to leave only
the text I care about:

output | egrep "Mac Address|Hub Id|Model" | sed "s/^.*[ ]//"



That gives me vertical output like below (many more lines than this):

00:12:34:56:78:9A

101

123456

00:21:CE:54:22:7A

101

876543

00:21:32:43:54:87

1

234



I would like to combine this output 3 lines at a time, like:

00:12:34:56:78:9A 101 123456

00:21:CE:54:22:7A 101 876543

00:21:32:43:54:87 1 234



Is there a way to do this using sed?



Thanks,

Dave







[Non-text portions of this message have been removed]
Jim Hill gjthill@gmail.com [sed-users]
2017-05-23 00:32:19 UTC
Permalink
output|sed -nE '/^Mac Address|^Hub Id|^Model/ s/.* //p' | sed
'N;N;s/\n/ /g'


[Non-text portions of this message have been removed]
Tim Chase sed@thechases.com [sed-users]
2017-05-23 00:37:11 UTC
Permalink
Post by 'Van Handel' ***@comcast.net [sed-users]
00:12:34:56:78:9A
101
123456
00:21:CE:54:22:7A
101
876543
00:21:32:43:54:87
1
234
00:12:34:56:78:9A 101 123456
00:21:CE:54:22:7A 101 876543
00:21:32:43:54:87 1 234
Is there a way to do this using sed?
Yes:

sed 'N;N;s/\n/ /g' input.txt > output.txt

Change the space to whatever delimiter you want, such as tabs:

sed 'N;N;s/\n/\t/g' input.txt > output.txt


It doesn't gracefully handle any edge conditions where a field is
missing, but could be massaged to be a little smarter if needed.

-tim
Joel Hammer Joel@HammersHome.com [sed-users]
2017-05-23 00:59:47 UTC
Permalink
This seems to work

cat file | sed "N;N;s/\n/ /g"

This assumes no blank lines.

Joel
Hello. This is on Linux. I have a command that returns many
attributes for each set top box on a headend, but I only need the
MacAddr, HubId, and Model.
To get that info, I pipe the output to grep & sed like this to leave only
output | egrep "Mac Address|Hub Id|Model" | sed "s/^.*[ ]//"
00:12:34:56:78:9A
101
123456
00:21:CE:54:22:7A
101
876543
00:21:32:43:54:87
1
234
00:12:34:56:78:9A 101 123456
00:21:CE:54:22:7A 101 876543
00:21:32:43:54:87 1 234
Is there a way to do this using sed?
Thanks,
Dave
[Non-text portions of this message have been removed]
Loading...