Appending Consecutive lines

Hi,

I have a file containing a single field on every row. What I need is to append one on to the end of another, e.g.

The input file looks like this:

nnnnn
mmmmmm

nnnnn
mmmmmm

I need it to look like this:

nnnnn mmmmmm

nnnnn mmmmmm

Any ideas would be much appreciated, Thanks :smiley:

Try...

paste -d" " - - < infile > outfile

Or...

awk -v RS="" '{$1=$1};1' infile > outfile

Hi Ygor,

Thanks for this. The paste command is the one that works for me. The awk script outputs just one consecutive line but this might be how I've created my file...

Cheers, pondlife. :smiley:

Dear Ygor;

Can you please explain in some words the syntax you wrote??
specially the past command

i like your ways guys

For the AWK command.....

If my input file contains....

nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm

nnnnnnnn
mmmmmmmmmmmmmm

I use the command

awk 'BEGIN{RS="\n\n"} {printf("%s %s\n", $1, $2)}' infile > outfile

to produce the output

nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm
nnnnnnnn mmmmmmmmmmmmmm

Cheers
ZB

zazzybob,

Does this work on your file?

awk -v RS="" '{$1=$1};1' infile

Yes it does - I'm not too sure how the OP has his file constructed - I constructed mine exactly as per his original post.

I'm not sure how my original file was constructed but I've tried the awk one again and it works.. I do like the awk solutions because I really want to unravel the power of the language but I seem to be missing the quicker & simpler solutions in the process!
Thanks, pondlife

I've just realised why the awk command didn't work for me the first time - i'd put a space between the quotes of the RS declaration. i.e. RS=" " instead of the correct RS="". :slight_smile: