0

This post may be looked upon as a followup to a previous post.

This is input file:

module ABC   
x(a,b,c)  
module DEFG  
y(d,e,f,  
g,h,i)  
module HIJKL  
z(j,k,l)

And output file should be:

module ABC x(a,b,c)  
module DEFG y(d,e,f,  
g,h,i)  
module HIJKL z(j,k,l)

I tried using asterisk as a wildcard character in the solutions provided in the referenced post but it did not work as expected.


Addendum Upon closer examination I found out that indeed the solutions provided earlier work for me as well (as pointed out by @steeldriver). The problem was that the file originated from a DOS/Windows platform and there was an unexpected ^M character that got inserted into the output, which was messing up down-the-line processing for me. I have now run dos2unix on the input file and the problem has gone away (i.e. the previous solutions work for me as well).

I am recommending that this post be closed as duplicate.

Sandeep
  • 139
  • Why do you need a "wildcard character"? what exactly is unsatisfactory about the previous answers such as sed '/^module/N;s/\n//'? – steeldriver Dec 18 '20 at 17:44
  • Indeed the solutions provided earlier work for me as well (as pointed out by @steeldriver). Kindly see the addendum to my post regarding why I missed out on that. I am recommending that this post be closed as duplicate. – Sandeep Dec 18 '20 at 18:32
  • Closed the question as a duplicate of the question indicated, on request from the user (which makes sense to me too). – Kusalananda Dec 18 '20 at 18:50

1 Answers1

1

Here is a solution using awk :

awk '{if ($0 ~ /^module/) {ORS=""}  else {ORS="\r\n"} ; print}'
Reda Salih
  • 1,754