Search code examples
xmlrecord

How to convert these lines into one per line?


This question is really important since I need to present the data to my supervisor asap.

I have a list of records in this format:

Name
Date
Place

Name
Date
Place

I want these records into one line like this:

Name,Date,Place
Name,Date,Place

How can I achieve this under Linux by using awk or sed easily?

THANK YOU.


Solution

  • With Gnu AWK, you can do something like this -

    gawk -v RS='\n\n' -v FS='\n' -v OFS=',' '{print $1,$2,$3}' file
    

    Test:

    [jaypal:~/Temp] cat file
    Name
    Date
    Place
    
    Name
    Date
    Place
    [jaypal:~/Temp] gawk -v RS='\n\n' -v FS='\n' -v OFS=',' '{print $1,$2,$3}' file
    Name,Date,Place
    Name,Date,Place