Batch File: Removing carriage return from .tsv file -


i trying remove carriage return .tsv file using batch file. how .tsv file looks, first line column line

* **[cr] , [lf] shown in these lines manually added idea

class   name & address  item    lbs value   pickup/drop off date:   23 sep[cr][lf] class1  ben coha[cr]  2305 e la st[cr]  visia, pa[cr]  932112-4422    health , beauty product / cologne body wear men   0.13    19[cr][lf]       class2  mich marce[cr]  255 rid court[cr]  prince frick, pa[cr]  20442  health , beauty product / cologne body wear women 1.5 47   

i want file below [i used notepad remove('replace' nothing) occurrences of [cr] only]

class   name & address  item    lbs value   pickup/drop off date:   23 sep[lf] class1  ben coha 2305 e la st visia, pa 932112-4422 health , beauty product / cologne body wear men   0.13    19[lf]       class2  mic marce 255 rid court prince frick, pa 20442  health , beauty product / cologne body wear women 1.5 47   

i tried following batch file. file being put in 1 single line. removes both carriage return , line feed.

@echo off setlocal disabledelayedexpansion /f "delims=" %%a in (myfile.tsv) ( echo/|set /p ="%%a%" )>>newmyfile.tsv     

the result looks like..

class   name & address  item    lbs value   pickup/drop off date:   23 sepclass1    ben coha 2305 e la st visia, pa 932112-4422 health , beauty product / cologne body wear men   0.13    19      class2  mic marce 255 rid court prince frick, pa 20442  health , beauty product / cologne body wear women 1.5 47   

i want modify .bat file removes \r instead of removing both \r\n

update: somehow able add images, give clearer idea. similar .tsv file enter image description here want enter image description here

this trivial if use jrepl.bat regular expression text processing utility

jrepl \r "" /f "myfile.tsv" /o "newmyfile.tsv" 

you can overwrite original file if use /o -.

you must use call jrepl if put command within batch script.


below original answer when thought there cr/lf @ end of each line in source file (before question edited).

i hate editing text files batch, requires lot of arcane knowledge, has many restrictions, , result slow. however, possible solve batch, , decided use practice :-)

the following works provided each input line <= 1021 bytes long, , output lines < ~8191 bytes long.

@echo off setlocal enabledelayedexpansion set "input=test.txt" set "output=out.txt"  :: define lf contain linefeed character set ^"lf=^  ^"  empty line above critical - not remove  :: determine how many sets of 4 lines must read /f %%n in ('find /c /v "" ^<"test.txt"') set /a cnt=%%n/4  <"!input!" >"!output!" (    %= read , write first line =%   set "ln="   set /p "ln="   <nul set /p "=!ln!!lf!"    %= outer loop iterates 4 line sets =%   /l %%n in (1 1 !cnt!) (      %= initialize out line empty =%     set "out="      %= inner loop appends next 4 lines out =%     /l %%n in (1 1 4) (       set "ln="       set /p "ln="       set "out=!out!!ln!"     )      %= write line =%     <nul set /p "=!out!!lf!"   ) ) 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -