1

I have a file with the following data:

2.18521   
3.00948   
4.35773   
5.43936

And I would like it to look like this:

2.18521   3.00948   4.35773   5.43936

How can I implement this using the sed or any other command in linux? I could use:

sed  -i '2.18521      /2.18521/g' file

But this does not help since there are many numbers in the file with different numerical values and I cannot go through all of them.

I should add that, the data actually looks like this:

     0 0 0 0 0 0
     2.18521   
     3.00948   
     4.35773   
     5.43936

And I do not want anything to be done with the numbers above the block. The output should look like this:

     0 0 0 0 0 0
     2.18521   3.00948   4.35773   5.43936
Cyrus
  • 84,225
  • 14
  • 89
  • 153
eddy
  • 43
  • 6
  • Does this answer your question? [How do I remove newlines from a text file?](https://stackoverflow.com/questions/3134791/how-do-i-remove-newlines-from-a-text-file) – wjandrea Apr 30 '20 at 16:58
  • I assumed the indenting was one level too high by accident so I fixed it. LMK if I was wrong. – wjandrea Apr 30 '20 at 16:59
  • It partially does, Maybe I should expand more, there are some other numbers in the file that I would not like to touch. This command targets the entire file. Is there a way to achieve what I want using a modification of this command? – eddy Apr 30 '20 at 17:02
  • Well what do you want exactly? Please [edit] to clarify. – wjandrea Apr 30 '20 at 17:04
  • @wjandrea Looks more like OP wants to replace newlines with tabs or spaces, not completely strip them. There's probably a better duplicate. – Shawn Apr 30 '20 at 17:06
  • @Shawn I thought that too but there's trailing whitespace in the file snippet – wjandrea Apr 30 '20 at 17:07
  • I have edited the question to include more details. – eddy Apr 30 '20 at 17:08
  • 1
    Please add your desired output (no description) for that sample input to your question (no comment). – Cyrus Apr 30 '20 at 17:10
  • I have included an edit with the desired output. – eddy Apr 30 '20 at 17:14
  • Are the leading spaces part of the file? – Cyrus Apr 30 '20 at 17:14
  • Yes. those spaces do not affect the desired output. The main aspect is all the data below "0 0 0 0 0 0" being on the same line. – eddy Apr 30 '20 at 17:16
  • Yes. I have done that. I am still new to stack overflow hence the naivety. – eddy May 01 '20 at 19:05

1 Answers1

2

With GNU sed:

sed '1b; :a; N; s/\n//; ta' file

Output:

     0 0 0 0 0 0
     2.18521        3.00948        4.35773        5.43936
Cyrus
  • 84,225
  • 14
  • 89
  • 153