Split a txt file \n ?

savinio0

New member
Member
Local time
5:29 AM
Messages
73
want to split a txt file.First i open the txt file with notepad++ and i change from this \r\n to this \n , then i want to split them in 1o pieces and for that i use a tool called split or joinand also this script and when i check them i see are \r\n\ again.How to split a txt file \n and keep same \n ?
thanks guys
ur the besttt

Code:
@ECHO OFF
SETLOCAL
SET "sourcedir=C:\Documents and Settings\Admin\Desktop\split files"
SET /a fcount=100
SET /a llimit=10000
SET /a lcount=%llimit%
FOR /f "usebackqdelims=" %%a IN ("%sourcedir%\list.txt") DO (
 CALL :select
 FOR /f "tokens=1*delims==" %%b IN ('set dfile') DO IF /i "%%b"=="dfile" >>"%%c" ECHO(%%a
)
GOTO :EOF
:select
SET /a lcount+=1
IF %lcount% lss %llimit% GOTO :EOF
SET /a lcount=0
SET /a fcount+=1
SET "dfile=%sourcedir%\file%fcount:~-2%.txt"
GOTO :EOF
 

My Computer

Computer type
PC/Desktop
OS
windows xp c86
Windows tools like to end lines with \r\n. This behavior extend back through more than three decades of Windows and DOS history. The \r is pointless, useless, and annoying. But it's there.

Unix/Linux uses only \n at line-end. Smart.

Question: Why do you need to need to remove the \r characters? You're showing a .bat script, meant to work in Windows, which wants (and expects) the \r\n line endings.

Nevertheless, if you really must remove the \r characters, get a Linux environment. I use Cygwin. It runs NATIVELY on Windows. It's from Red Hat and it's free. You get the a complete Linux-like environment, suitable for doing your \r-killing work ... and it will do much more.

I can be installed to produce files in a Windows-sh \r\n manner. But that's silly. Instead, during installation choose the more natural Unix/Linux \n behavior.

If you can find the "d2u" dos-to-unix command online, use it to eliminate the \r\n endings:
d2u <inputfile >outputfile
You can also do the reverse (change \n to \r\n) using the "u2d" unix-to-dos command.

If you cannot find the d2u command, you can instead use the "tr" translate command:
tr -d "\r" <inputfile >outputfile
This will simply remove all \r characters.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell
OS
Windows 10 x64
CPU
i7-7700K
Memory
16 GB 2400 MHz
Graphics Card(s)
GTX 1060
Sound Card
Integrated, plus external Presonus Audiobox USB
Monitor(s) Displays
2x AOC 27"
Screen Resolution
1920x1080
Hard Drives
512 GB M.2 SSD
2 TB 7200 RPM disk
Internet Speed
110 Mbps
Browser
Firefox
Back
Top