Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Move next line to current line after "+"

I have text file with data as you can see below

  1  0.751E-04  0.000E+00  0.113E-04  0.735E-05 -0.530E-05  0.410E-06 -0.805E-06      +
    -0.442E-06  0.476E-06 -0.252E-06
  2  0.792E-04  0.000E+00  0.134E-04  0.680E-05 -0.504E-05  0.435E-06 -0.895E-06      +
    -0.216E-06  0.149E-06 -0.133E-06

I want to move the line after + to the above or current line as shown below

  1  0.751E-04  0.000E+00  0.113E-04  0.735E-05 -0.530E-05  0.410E-06 -0.805E-06 -0.442E-06  0.476E-06 -0.252E-06
  2  0.792E-04  0.000E+00  0.134E-04  0.680E-05 -0.504E-05  0.435E-06 -0.895E-06 -0.216E-06  0.149E-06 -0.133E-06

I tried awk using below code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

awk '{if($0 ~ /+/) print $0; getline; print}' A1.txt

With this code I get the output same as the input and the line/row is not moving up.

I also tried tr

 tr '      +' ' ' < A1.txt >> ddg.txt

But got the same as output without the + sign.

I can share an example input file but I do not see an option here. Can I upload it in google drive and share the link or would that be against the forum’s rules?

>Solution :

With :

awk 'BEGIN{RS="\n\n"}{gsub(/\+\n/, "")}1' file

With GNU : Credit to jhnc

sed -z 's/+\n//g' file

With :

perl -0777 -pe 's/\+\n//g' file
  1  0.751E-04  0.000E+00  0.113E-04  0.735E-05 -0.530E-05  0.410E-06 -0.805E-06           -0.442E-06  0.476E-06 -0.252E-06
  2  0.792E-04  0.000E+00  0.134E-04  0.680E-05 -0.504E-05  0.435E-06 -0.895E-06           -0.216E-06  0.149E-06 -0.133E-06
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading