Adjust right margin size in text editor notepad

fjkaykr11
fjkaykr11 used Ask the Experts™
on
I am looking for a way to edit Microsoft Windows notepad or another text editor so that I can increase the right margin size, so the number of characters displayed on each line is shorter in length and will wrap to the next line.  The word wrap is working correctly but the right margin length is not.  I tried to do this in notepad text editor by going to File > Page Setup and also checking off word wrap but it isn't working.
I need to copy a lot of text info from notepad to Excel and I want to have it so the text length isn't too  long in Excel.
Does any have an idea how I can do this in notepad or another ascii text editor. Right now I have to do this manually but going into notepad and click on enter about halfway through each line so the text will wrap to the next line, so when I copy it over to Excel it will display the way I want it.   Thanks for the info.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
GrahamSkanRetired
Top Expert 2012

Commented:
Do you also have MS Word? You can open text files in Word and set the paragraph indent.

If you have a large number of input files, it might be worth using a VBA macro to do the job.

Author

Commented:
I can't get it to work properly in Word, only Notepad. With Microsoft word when I copy it over it will insert all the lines into one row in Excel, unless I do a lot of manually editing, hiting the Enter key on each line. In Notepad it works ok, it will insert a line with Word Wrap,  but then have to manually hit enter where I want to end the line.
I need to be able to copy text info from notepad or another editor to Excel so it will have multiple lines but the text length is shorter.

Commented:
Word Wrap operations are VIEW only operations. It doesn't actually alter the text content, which in your case is necessary.
First download notepad++: https://notepad-plus-plus.org/downloads/
When you opened your text file, use the Find & Replace function (CTRL+h):

Find:      (?<=.{80})\s
Replace:   $0\n
Make sure the lower radio button with Regular Expression is used! Then click "Replace All"

If it's too wide or too shallow, edit the 80 (it will break around the 80 characters mark, when a space is nearby)
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Author

Commented:
@Kimputer thanks for the info.  I followed the steps you indicated (including selecting Regular Expression) but when I try to do the replace the Notepad++ Replace feature just highlights the first word in the text of the file, and does not do anything else. I attached as sample file.  Any ideas?
Test1.txt

Commented:
Have the cursor at the very start of the file. Make sure the Find What:  IMMEDIATELY starts with (?<=.{80})\s (so "(" is the first character)

Author

Commented:
Ok I am making progress by following the steps you mentioned. Once it replaces the characters I am saving the file in Notepad++
as text2.txt. However, it doesn't seem to adjust the line length (right margin) for the text when I open the new file in notepad, it was the same length after viewing in notepad. I tried it with the value of 80 and then again with 40.  I went ahead and manually adusted the second file test2.txt and uploaded it, that is how I need it to
look (with much shorter lines).
Test2.txt

Author

Commented:
Just to add, I am not opposed to doing this with another method such as using Microsoft Word or another method. However, when I copy the text over to Excel, it will add all the lines into one row. So I am looking for whatever method will work, to display each line as a new row in Excel. I am doing this with a lot of info, and files, so it takes quite a bit of time to have to go through manually and hit enter when doing this is in Notepad.  Thanks again.
I was able to resolve this using PowerShell.  The code I used was:
 (gc in.txt) -replace ".{100}" , "$&`r`n" | sc out.txt

You can adjust the # 100 accordingly. I also needed to remove extra blank lines and I resolved in Microsoft Word using find: ^p^p with ^p.  I am working with many files so this is going to save me a lot of time. Thanks for assistance.
Commented:
My solution is still better if you adjust it slightly.

Find: (?<=.{80})\s
Replace: $0\r\n

That's because you use REAL WORLD words. They will break up in your solution, but stay "whole" in mine.
Ex. if around 80 characters you have a long word like "antidisestablishmentarianism", your solution may have this in line 1: antidise
and this in line 2: stablishmentarianism
In my solution that will never happen.

Author

Commented:
@Kimputer thanks for the updated info, often I find some don't follow up when the first solution doesn't work.
I was able to get this to work with your method as well with the updated step you provided.  I like having both options Notepad++ and Powershell.
i prefer scripts if possible,  so I can run this on a lot of files at once, next I want to figure out how to remove the tabs and empty blank lines without doing those steps in Microsoft Word. But for now fixing the margin issue is a huge help.  Thanks again.

Commented:
Notepad++ does macros. You can use the first find and replace for the shortening of the lines, and you can add another find and replace for the extra lines.
The extra lines are this btw:

find: \r\n\r\n
replace: \r\n

Author

Commented:
awesome info, thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial