Shell script to convert rows into cloumns

B010215861628
MA
01020
CARRIER

B010215861695
MA
01020
CARRIER

B010215861709
MA
01020

CARRIER

My output is in the above format

I want the output to be:

B010215861628,MA,01020,CARRIER
B010215861695,MA,01020,CARRIER
B010215861709,MA,01020,CARRIER

Thanks
Prathyu

Welcome to the forum.

Any attempts / ideas / thoughts from your side?

Indeed welcome Teegela Prathyu ,

I too have a few to questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

As a pointer to working through the logic needed:-

  • Is every 'record' made from four lines? Are we absolutely certain?
  • Can we ignore blank lines?
  • Is there a clear marker that we're starting a new 'record'? e.g. the line starts B01 or ends CARRIER

Kind regards,
Robin

Hi Teegela Prathyu...

I have no idea how many times this has been asked but a simple search of THIS site alone brought this up:-

From that it should be possible to adapt this existing knowledge for your needs.

Or, look at the bottom left of this page: "More UNIX and Linux Forum Topics You Might Find Helpful" ...