Discussion:
change paragraphs to long lines
George Georgalis
2013-11-05 06:36:41 UTC
Permalink
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/
Thierry Blanc
2013-11-05 08:20:36 UTC
Permalink
try

sed -r '/^$/!{:a;N;/\n$/b;s|\n| |;ba}'
Post by George Georgalis
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.
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
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/
Davide Brini
2013-11-05 09:21:48 UTC
Permalink
Post by George Georgalis
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.
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
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?
A simple way would be (gnu sed)

sed ':a; $!{N;ba;}; s/\n\n/\x1/g; s/\n/ /g; s/\x1/\n\n/g'

or without slurping the file:

sed ':a; $b; N; /\n$/b; s/\n/ /; ba'
--
D.
George Georgalis
2013-11-06 05:12:54 UTC
Permalink
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
Post by George Georgalis
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.
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
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
2013-11-06 20:00:34 UTC
Permalink
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
-----------------------
Post by George Georgalis
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
Post by George Georgalis
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.
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
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/
prem
2013-11-06 20:36:20 UTC
Permalink
 
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
 
 
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
-----------------------
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
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.
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
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/
Daniel Goldman
2013-11-06 21:29:47 UTC
Permalink
Let's hope this one makes it to the list. Last time, I forgot the default is to email the
person (private email), not the list.
Post by prem
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
I modified your syntax some, there were some syntax mistakes (look below), but I agree it
is a simpler way.

$ 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

$ tr "\n" "~" < input | sed -e 's/~~/\n\n/g' -e 's/~/ /g'
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

Daniel
Michael Hauser
2013-11-16 22:21:30 UTC
Permalink
Not that I've had the time to try this beautiful little snippet of code,
but I am too hopeful that this or something similar makes it into the
sed1line.txt, where it would've spared me hours of figuring it out by
myself!

☺

*winks to sven*


cheers, mih
Post by Daniel Goldman
Let's hope this one makes it to the list. Last time, I forgot the default is to email the
person (private email), not the list.
Post by prem
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
I modified your syntax some, there were some syntax mistakes (look below), but I agree it
is a simpler way.
$ 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
$ tr "\n" "~" < input | sed -e 's/~~/\n\n/g' -e 's/~/ /g'
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
Daniel
--
'aware water' is an anagram for 'we are at war'
Loading...