Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-15-2003, 07:13 PM   #1
Registered: Sep 2002
Location: Seattle, WA
Distribution: Ubuntu
Posts: 101

Rep: Reputation: 15
using sed to remove word wrap

I have a file that was previously formatted with word wrap such that it has a newline at a certain row length, like this:


`Thank you, it's a very interesting dance to watch,' said
Alice, feeling very glad that it was over at last: `and I do so
like that curious song about the whiting!'

`Oh, as to the whiting,' said the Mock Turtle, `they--you've
seen them, of course?'

`Yes,' said Alice, `I've often seen them at dinn--' she
checked herself hastily.

`I don't know where Dinn may be,' said the Mock Turtle, `but
if you've seen them so often, of course you know what they're

`I believe so,' Alice replied thoughtfully. `They have their
tails in their mouths--and they're all over crumbs.'

`You're wrong about the crumbs,' said the Mock Turtle:
`crumbs would all wash off in the sea. But they HAVE their tails
in their mouths; and the reason is--' here the Mock Turtle
yawned and shut his eyes.--`Tell her about the reason and all
that,' he said to the Gryphon.

`The reason is,' said the Gryphon, `that they WOULD go with
the lobsters to the dance. So they got thrown out to sea. So
they had to fall a long way. So they got their tails fast in
their mouths. So they couldn't get them out again. That's all.'


Is there a way to use sed, or another editor to automatically remove this newline so that each paragraph is on it's own line?

Old 10-16-2003, 03:37 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try this out (probably an easier way - I just can't think of it):
cat /path/to/file | echo -n `sed 's/^$/STARTPARA/'`|sed 's/STARTPARA/\n\n/g'
Old 03-02-2009, 07:53 PM   #3
Registered: May 2006
Location: Brisbane, Australia
Distribution: linux
Posts: 157

Rep: Reputation: 44
Originally Posted by david_ross View Post
Try this out (probably an easier way - I just can't think of it):
cat /path/to/file | echo -n `sed 's/^$/STARTPARA/'`|sed 's/STARTPARA/\n\n/g'
Try this for a single paragraph

tr -s ' \009\012' ' '


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
restricted word wrap with Kontact (Kmail) blastradius Linux - Software 2 10-21-2005 08:39 AM
Microsoft Word won't word wrap Micro420 General 1 06-13-2005 05:36 PM
word wrap in java linux_ub Programming 3 08-11-2004 02:16 AM
Word Wrap Squall LQ Suggestions & Feedback 4 02-03-2004 04:25 PM
sed help, replacing a letter with a word GridX Linux - Newbie 1 09-24-2003 11:21 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration