Split a txt file \n ?


  1. Posts : 73
    windows xp c86
       #1

    Split a txt file \n ?


    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


  2. Posts : 318
    Windows 10 x64
       #2

    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


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 10:03.
Find Us