Concatenation of a line to previous line

I need to concatenate all lines of a file into 1 line.
input file containing lines like

001123456400001234563 107 001578000000000000000000000000000000000000 0000000021600 
001123456912345600003 107 001578000000000000000000000000000000000000 0000000992000 

i am using command

echo `awk '{ printf ("%s",$0) }' infile`> outfile

its working fine but converting number of spaces to 1 like if file having 12 spaces its counting 1. I want record length should not altered while concatnating the lines. Kindly help.

Output file should be in one line with same number of spaces as in input file like:

001123456400001234563 107 001578000000000000000000000000000000000000 0000000021600 001123456912345600003 107 001578000000000000000000000000000000000000 0000000992000

Here also i am not able to display correct number of spaces(displaying only 1 space)

Try below

paste -s inputfile

This one is simple :slight_smile:

cat infile | tr '\n' ' ' > outfile 

The using of cat is superfluous:

tr '\n' ' ' < infile > outfile

Yes, this works just like my previous command...but there is a SPACE introduced btw the joined lines. Is there an option to avoid it.

example:
line 1: aaaaaaaaaa
line 2: bbbbbbbbbb
line 3: cccccccccc

output: aaaaaaaaa bbbbbbbbbb cccccccccc

Expected output: aaaaaaaaabbbbbbbbbbcccccccccc

Try:

tr -d '\n' < file > newfile

or:

awk '1' ORS= file > newfile

If you want a newline at the end of the line:

awk '1;END{print "\n"}' ORS= file > newfile
perl -i -pe 's/[\n\r]/ /g' input_file