help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to combine lines into paragraphs?


From: Peng Yu
Subject: Re: How to combine lines into paragraphs?
Date: Fri, 9 Sep 2022 10:17:07 -0500

Here is what I have currently. I am not sure if there is any better
way to implement it?

{
    if(/^$/) {
        if(line != "") {
            if(!printed) {
                printed = 1
            } else {
                print ""
            }
            print line
            line = ""
        }
    } else {
        if(line == "") {
            line = $0
        } else {
            line = line " " $0
        }
    }
}
END {
    if(line != "") {
        if(!printed) {
            printed = 1
        } else {
            print ""
        }
        print line
    }
}

On Fri, Sep 9, 2022 at 9:56 AM Peng Yu <pengyu.ut@gmail.com> wrote:
>
> Hi,
>
> ===
> line1
> line2
>
>
> line3
> line4
> ===
>
> For example, for the above input, the output should be the following
>
> ===
> line1 line2
>
> line3 line4
> ===
>
> What is the most succinct way to do so in awk?
>
> --
> Regards,
> Peng



-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]