Skip to main content
3 of 8
added 199 characters in body
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

What you want to do is to join the module lines with the next line.

Using sed:

$ sed '/^module/N;s/\n//' file
module  x(a,b,c)
module  y(d,e,f,
g,h,i)
module  z(j,k,l)

This is with your data copied and pasted as is, with spaces at the end of each line.

The sed command will print each line as it is read, but when it encounters a line that starts with the string module, it appends the next line with an embedded newline character in-between (this is what N does). We remove that newline character with a substitution.

If your data has no spaces at the end of the lines, use

$ sed '/^module/N;s/\n/ /' file
module x(a,b,c)
module y(d,e,f,
g,h,i)
module z(j,k,l)

Just in case you'd want this (assuming no spaces at end of input lines):

$ sed -n '/^module/ { x; s/\n/ /g; /^$/d; p; d; }; H; $ { x; s/\n/ /g; p; }' file
module x(a,b,c)
module y(d,e,f, g,h,i)
module z(j,k,l)
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k