Merge text files & then sort unique in DOS
On Tue, 4 Sep 2018 10:16:57 -0500, Grease Monkey wrote:
Merging text files is easy in DOS
for %f in (*.txt) do type "%f" output.txt
But how do you sort unique in DOS?
You can sort the contents of a text file using the SORT program. e.g.
type file.txt | sort
But removing duplicate lines is not possible using SORT, because it simple
doesn't have such capability built it.
So, you'll have to check for duplicates manually from a batch file. e.g.
@echo off
setlocal enabledelayedexpansion
:: sort contents
type output.txt | sort sorted.txt
set line=
del unique.txt 2nul
for /f "delims=" %%A in ('type sorted.txt') do (
if not "%%A" == "!line!" (
echo %%A unique.txt
set line=%%A
)
)
Note that this is problematic if the file contains double quote (")
character. In this case, I'd suggest using JScript.
|