Re: change paragraphs to long lines
prem <[email protected]>
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <[email protected]> |
Would not something like this do the same in a simpler way? You may have to use something other than "~" if you think it might already exist in the input. tr "\n" "~" input | sed -e '/s/~~/\n/g' -e '/~/ /g' > output From: George Georgalis <[email protected]> >To: [email protected] >Sent: Wednesday, November 6, 2013 2:00 PM >Subject: Re: change paragraphs to long lines > > > > > > >Here's the private email, the author intended it for the list. Regards, George > > >--------------------------------------- > >$ cat input >ONE two three one two three one two three one >TWO three one two three one two three one two >THREE one two three one two three one two > >ONE two three one two three one two three one >TWO three one two three one two three one two >THREE one two three one two three one two > >ONE two three one two three one two three one >TWO three one two three one two three one two >THREE one two three one two three one two >$ sed 's/^ *$/UNIQ_STR/' input | tr "\n" " " | sed 's/ UNIQ_STR /\n\n/g' | sed '$ s/ $/\n/' >ONE two three one two three one two three one TWO three one two three one two three one two THREE one two three one two three one two > >ONE two three one two three one two three one TWO three one two three one two three one two THREE one two three one two three one two > >ONE two three one two three one two three one TWO three one two three one two three one two THREE one two three one two three one two >----------------------- > > > >On Tue, Nov 5, 2013 at 9:12 PM, George Georgalis <[email protected]> wrote: > >Thanks Thierry, Davide and private email! >> >> >> >>I used all your input. From the private email, a longer way of Davide's method, which helped me see the algorithm and get to the understanding the others failed due to DOS format. After fixing the line endings, I ended up going with Thierry's method since it seemed to handle leading blank lines better: sed -r '/^$/!{:a;N;/\n$/b;s|\n| |;ba}' >> >> >>Big help, I think I will add this as a macro in my editor. And I vote to add it to the sed1line file! >> >> >>Regards, >>-George >> >> >> >>On Mon, Nov 4, 2013 at 10:36 PM, George Georgalis <[email protected]> wrote: >> >>Hello sed list, hope you are all well. >>> >>> >>>Long time subscriber but I've not been following lately, hope this hasn't come up recently. >>> >>> >>>I have a file with double returns to denote paragraphs. I'd like to retain the double returns but join all the other lines, so paragraphs have long lines. >>> >>> >>> >>> >>>so this: >>>one two three one two three one two three one >>>two three one two three one two three one two >>>three one two three one two three one two >>> >>> >>> >>>one two three one two three one two three one >>>two three one two three one two three one two >>>three one two three one two three one two >>> >>> >>> >>>changes to this: >>>one two three one two three one two three one two three one two three one two three one two three one two three one two three one two >>> >>> >>>one two three one two three one two three one two three one two three one two three one two three one two three one two three one two >>> >>> >>>Maybe this solution would good for the sed1line file? >>> >>> >>>Regards, >>>-George >>> >>> >>> >>>-- >>>George Georgalis, (415) 894-2710, http://www.galis.org/ >> >> >> >> >>-- >>George Georgalis, (415) 894-2710, http://www.galis.org/ > > > > >-- >George Georgalis, (415) 894-2710, http://www.galis.org/ > > > > >