Linux - NewbieThis forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi
I need a SED line to insert \n (newline) after nth character of a line.
My goal is to simulate word wrap.
Suppose that I have a line like this:
You should include as much detail as possible in your message, including exact error messages (where applicable) and what you have done so far.
I want it as follows:
You should include as much detail as possible (\n)
in your message, including exact error messages (\n)
(where applicable) and what you have done so far. (\n)
In this example the sum of characters for each line is 50
Worked near to perfect
But may not work if the word containing the 45th chr is very long. Therefore counting 50 chars than returning to the last occurance of "SPACE" or;
replacing the occurance closest (but before) to 50th chr of "SPACE" with "NEWLINE" may handle the problem better I think.
You should include as much detail as possible in your message, including exact error messages (where applicable) and what you have done so far.
I want it as follows:
You should include as much detail as possible (\n)
in your message, including exact error messages (\n)
(where applicable) and what you have done so far. (\n)
In this example the sum of characters for each line is 50
Appreciate very much any help
Best
You may be interested in the "fold" command, which is included with almost any GNU system.
Code:
fold -s -w 50 textfile.txt
This would wrap at 50 characters, but only at spaces, so as not to chop words in the middle.
See "man fold" for more info.
Regards
Gilbert
Last edited by Tinkster; 04-15-2009 at 05:51 PM..
Reason: [mod_edit]shameless plug removed ;)
The "fold" command is good, but it only breaks long lines.
If you are going to use a linux command, the better one is "fmt" which has options to fill-out short lines, specify margins, and prefix strings, and also remove extra spaces between words.
The "fold" command is good, but it only breaks long lines.
If you are going to use a linux command, the better one is "fmt" which has options to fill-out short lines, specify margins, and prefix strings, and also remove extra spaces between words.
Basically it can do what "fold" does, and more.
Oooo... now fmt is cool. I really like the filling out of short lines, and uniformed spacing. Interestingly, it won't add an extra space between sentences that only have one space, however it does remove extra spaces between sentences nicely. I can think of an easy sed command to fix the former, anyway. Great suggestion, thanks!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.