6

I have a log file that displays data 3 lines at a time. Like this:

1 data 2 data 3 data 1 data 2 data 3 data 1 data 2 data 3 data 

I'd like to take each 3 lines and display them on 1 line like this:

1 data 2 data 3 data 1 data 2 data 3 data 1 data 2 data 3 data 

I'd like to be able to cat this file and then pipe it through a command(s) that will do this for me. I suspect sed or awk are a solution.

0

3 Answers 3

10

You might be able to use paste:

$ paste - - - <data.txt 1 data 2 data 3 data 1 data 2 data 3 data 1 data 2 data 3 data 
1
  • Paste is exactly what I was looking for, thank you. Commented Feb 26, 2016 at 20:46
2

Here's one way:

$ perl -pe 's/\n/ / unless $. % 3 == 0' file 1 data 2 data 3 data 1 data 2 data 3 data 1 data 2 data 3 data 
0
2

Or also sed by "N"omming two lines and then nixing the newlines in the resulting buffer.

sed 'N;N;s/\n/ /g' 
1
  • Nomming. Love it. Commented Feb 27, 2016 at 1:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.