Issue
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
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:
awk 'BEGIN{RS=""}{gsub(/ +\+\n +/, " ")}1' file
With GNU
sed:
sed -z 's/ \++\n \+/ /g' file
With perl:
perl -0777 -pe 's/\s+\+\n\s+/ /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
Answered By - Gilles Quénot Answer Checked By - Marie Seifert (WPSolving Admin)