Search code examples
linuxcommand-linecommand-line-tool

Need to create a single record from 3 consecutive lines of text


I can easily write a little parse program to do this task, but I just know that some linux command line tool guru can teach me something new here. I've pulled apart a bunch of files to gather some data within such that I can create a table with it. The data is presently in the format:

        .serviceNum=6360,
        .transportId=1518,
        .suid=6360,
        .serviceNum=6361,
        .transportId=1518,
        .suid=6361,
        .serviceNum=6362,
        .transportId=1518,
        .suid=6362,
        .serviceNum=6359,
        .transportId=1518,
        .suid=6359,
        .serviceNum=203,
        .transportId=117,
        .suid=20203,
        .serviceNum=9436,
        .transportId=919,
        .suid=16294,
        .serviceNum=9524,
        .transportId=906,
        .suid=17613,
        .serviceNum=9439,
        .transportId=917,
        .suid=9439,

What I would like is this:

.serviceNum=6360,.transportId=1518,.suid=6360,
.serviceNum=6361,.transportId=1518,.suid=6361,
.serviceNum=6362,.transportId=1518,.suid=6362,
.serviceNum=6359,.transportId=1518,.suid=6359,
.serviceNum=203,.transportId=117,.suid=20203,
.serviceNum=9436,.transportId=919,.suid=16294,
.serviceNum=9524,.transportId=906,.suid=17613,
.serviceNum=9439,.transportId=917,.suid=9439,

So, the question is, is there a linux command line tool that will somehow read through the file and auto remove the EOL/CR on the end of every 2nd and 3rd line? I've seen old school linux gurus do incredible things on the command line and this is one of those instances where I think it's worth my time to inquire. :)

TIA

O


Solution

  • Use cat and paste and see the magic

    cat inputfile.txt | paste - - -