I have a data file with a fixed record length. There are no carriage returns or line feeds delimiting the records. How can I insert a carriage return linefeed pair at every X characters using Notepad++(where X is the record length)?
5 Answers
I appreciate that it's not ideal, but I'm surprised no one offered this as a pure N++ solution
In a regular expression find/replace
Find:
(.{750})
Replace:
$1\r\n
Roughly translated as...
Find:
750 instances of any character and remember the characters.
Replace:
The 750 characters we just remembered followed by a new line.
Although, to be honest, I'd stick to the powershell approach for anything more than a one-off run.
-
2Google brought me here. This worked great for a one-off document I had to split and diff! Thank you very much. Aug 27, 2014 at 18:40
-
4
This isn't a task suited to Notepad++, particularly with large input files. Using Windows PowerShell (available for free from Microsoft for Windows XP and Windows Vista, and included with Windows 7), you could do this with:
(gc in.txt) -replace ".{750}" , "$&`r`n" | sc out.txt
-
4I am new to PowerShell. Could you break down the various elements of the command and comment what they do?– DaveBNov 24, 2010 at 23:13
-
@DaveB 1. Parens are evaluated first, wherein gc command gets content from the file (in.txt). 2. replace command does a replace, taking first argument ("." for any character, {750} for 750 times), and replacing with second (found string ($) and tacks on carriage return+line feed (
r
n)). 3. This is then sent aka piped ("|") to the next statement. 4. sc command then sets content to the file parameter (out.txt).– troyDec 4, 2018 at 19:27
Notepad++ v5.8.3 has this command: first select the whole file; then
Edit -> Line Operations -> Split Lines
This splits lines so that they fit exactly in the current window. As far as I can see, you have to use the mouse to resize the window to the width that you want.
-
This doesn't work anymore. :'( They get split at the light blue line no matter how wide your window is– endolithJan 14, 2016 at 21:17
-
Looks like there is an option to set the blue line notepad-plus-plus.org/community/topic/3/…. Mar 21, 2019 at 12:04
For V6.3
Frame Window to Text Length
Highlight [ALL Text] >>Edit > Select ALL
Edit> LineOperations > SplitLine
Save Document under NEW NAME.
Type the number of characters you want on each line, select it, and then choose Edit → Cut.
Edit → Select All, then TextFX → TextFX Edit → ReWrap Text to (Clipboard or 72) width
TextFX → TextFX Edit → Trim Trailing Spaces
-
My records are 750 characters. After following your instructions, I am left with records of various lengths. Testing with a length of 10 characters leaves me with lines as short as 1 after trimming off the trailing spaces :( I am using version 5.7 of Notepad++.– DaveBNov 22, 2010 at 21:53
-
This doesn't work for me. It always wraps to 72 characters regardless of what's in the clipboard– endolithJan 14, 2016 at 21:21