Home > Mobile >  I want to remove newline character if the line not start with a space by unix command
I want to remove newline character if the line not start with a space by unix command

Time:11-24

Input:

 NOR2X2 U68695 
(n102890)
 AO21X4 U68696 ( .
A0(mbw4[84])
311)

Output:

 NOR2X2 U68695 (n102890)
 AO21X4 U68696 ( .A0(mbw4[84])311)

CodePudding user response:

Here is an awk to do that:

awk '/^[[:space:]]/{if (s) print s; s=$0; next}
{s=s $0}
END{ print s }' file 

Or a perl:

perl -0777 -lpE 's/(^\h[\s\S]*?)(?=^\h|\Z)/$1=~s|\n||gr."\n"/gme' file

Either prints:

 NOR2X2 U68695 (n102890)
 AO21X4 U68696 ( .A0(mbw4[84])311)

CodePudding user response:

OAI211X1 U77573 ( .A0(n115987) NAND2X2 U77574 ( .A(n113218), NAND2X2 U77575 ( .A( n113223), .B(n115976), .Y(n115988) ); AOI21X1 U77576 ( .A0(n117247), .A1(n 117197), .B0(n117211), .Y(n117200) ); OAI21X1 U77577 ( .A0(n117214), .A1(n117193), .B0(n117248), .Y(n117197) );

  •  Tags:  
  • bash
  • Related