windows - Batch file to sort txt after appending from other txt -


i'm wanting batch file can drag text file onto (preferrably multiple text files @ once) read each text file line line , add each line specified destination text file. destination text file not contain duplicated lines, , sorted alphabetically. source file never contain same line twice, may contain non-alphanumeric characters such as: { - : _ ~ !

example:

a.txt:

apple banana garbage carrot {elmer fudd} 

b.txt

1 tequila 2 tequila 3 tequila garbage carrot {bugs bunny} 

destination.txt before:

{daffy duck} floor 

destination.txt after dragging a.txt , b.txt onto batch file:

{bugs bunny} {daffy duck} {elmer fudd} 1 tequila 2 tequila 3 tequila apple banana floor garbage carrot 

i've got started:

@echo off setlocal disabledelayedexpansion set "sourcefile=%~1" echo "%sourcefile%" > temp.txt /f "delims=;" %%f in (%sourcefile%) (     echo %%f>>temp.txt )  del /q destination.txt ren temp.txt destination.txt 

it copies file dragged temp file, can't figure out how sorted. sort command not work me, hangs program up. appreciated. thank you!

@echo off setlocal enabledelayedexpansion set "prev=" echo "%~1" copy /y destination.txt+"%~1" temp.txt >nul  (     /f "delims=" %%f in ('sort temp.txt') (   if "!prev!" neq "%%f" echo(%%f   set "prev=%%f" ) )>destination.txt del temp.txt 

should work (i've not tried it)

no need process new file for /f - copy a+b c concatenates , b c. /y forces overwrite of destination if exists.

then process each line, echoing line read sort if line not match previous - "enclosing strings in quotes" batch knows process string single unit if contains spaces or other separators.

the (...echo ...)>file format (re)creates file echoed data rather sending data screen.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -