How can I remove a line-feed/newline BEFORE a pattern using sed

前端 未结 5 1997
悲哀的现实
悲哀的现实 2021-01-02 17:34

The title already states it:

I want to use some linux one liner (e.g. sed)

to transform

Anytext
{

into

Anyt         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 18:18

    One way using sed:

    sed -ne '$! N; /^.*\n{/ { s/\n//; p; b }; $ { p; q }; P; D' infile
    

    A test. Assuming infile with content:

    one
    Anytext
    {
    two
    three
    {
    four
    five
    {
    

    Output will be:

    one
    Anytext{
    two
    three{
    four
    five{
    

提交回复
热议问题