Multi lines to single line

HI,
My input file contains the data as like below:

A1234119993
B6271113
Bghjkjk
A1234119992
B6271113hi
Bghjkjkmkl

the output i require is :

A1234119993 B6271113 Bghjkjk
A1234119992 B6271113hi Bghjkjkmkl

Please help me in this.

Thanks

insert a line break whenever "A" is the first character in the line:

awk ' /^A/ && ok {print ""}
       /^A/ {ok=1}
       {printf("%s ",$0) } ' inputfile
1 Like

Awesome!!can you please explain this code?

Thanks

Hi Pandeesh

You can also try the following

code:

paste -s -d" " < filename

I dont think this will work.you are not checking any condition here.

---------- Post updated at 11:07 PM ---------- Previous update was at 09:38 PM ----------

there is a small change:

A1234119993 
B6271113 
Bghjkjk 
A1234119992 
B6271113hi 
Bghjkjkmkl

the output i require is :

  A1234119993 B6271113 
  A1234119993 Bghjkjk 
  A1234119992 B6271113hi 
  A1234119992 Bghjkjkmkl   

How we can achieve this?

Thanks

awk '
/^A/ { begin=$0  }   # line start A
/^B/ { print begin $0  }     # line start B
' inputfile
1 Like

I'm sorry Pandeesh

For your previous requirement the code will be like:-

paste -s -d"  \n" < filename

Note:There should be two spaces and one new line as delemeter , I have only checked it in Redhat Enterprise4 (LINUX).