Page 1 of 1

Sorting text file content with batch script,.

Posted: 10 Sep 2019 03:08
by Rajnishjc_27
Hi

I have data in filelist.TXT file as below.

"201804170930-ScottsDDSupplier.csv"
"201804180930-ScottsDDSupplier.csv"
"201804211030-ScottsDDSupplier.csv"

i need to sorting in Descending order when i read file as below..

@echo off
setlocal enableExtensions disableDelayedExpansion
set file=D:\filelist.txt

for /f "tokens=1 delims=" %%a in (%file% ) do (
echo %%a

)

so output should be like below ..
"201804211030-ScottsDDSupplier.csv"
"201804180930-ScottsDDSupplier.csv"
"201804170930-ScottsDDSupplier.csv"

how to handle with in batch script , please help

Re: Sorting text file content with batch script,.

Posted: 10 Sep 2019 03:51
by penpen
The following might help you:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
set "file=D:\filelist.txt"

sort /r "%file%"
penpen

Re: Sorting text file content with batch script,.

Posted: 10 Sep 2019 04:10
by Rajnishjc_27
Thank you Penpen,

one more need help , not i need only first record return ?

"201804211030-ScottsDDSupplier.csv"
"201804180930-ScottsDDSupplier.csv"
"201804170930-ScottsDDSupplier.csv"

Re: Sorting text file content with batch script,.

Posted: 10 Sep 2019 23:40
by Rajnishjc_27
Please Help on this.

Re: Sorting text file content with batch script,.

Posted: 11 Sep 2019 02:01
by penpen
Rajnishjc_27 wrote:
10 Sep 2019 04:10
one more need help , not i need only first record return ?
If understand right, that there are (contrary to your opening post) mutliple records per line in your file "filelist.txt", then that might help you:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
set "file=D:\filelist.txt"
set "file=test.txt"
for /f ^"delims^=^"^" %%a in ('sort /r %file%') do (
	echo "%%~a"
)
goto :eof

penpen

Re: Sorting text file content with batch script,.

Posted: 12 Sep 2019 00:58
by Rajnishjc_27
Thank you so much PenPen for your kind help.