Sorting text file content with batch script,.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

Sorting text file content with batch script,.

#1 Post by Rajnishjc_27 » 10 Sep 2019 03:08

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

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Sorting text file content with batch script,.

#2 Post by penpen » 10 Sep 2019 03:51

The following might help you:

Code: Select all

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

sort /r "%file%"
penpen

Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

Re: Sorting text file content with batch script,.

#3 Post by Rajnishjc_27 » 10 Sep 2019 04:10

Thank you Penpen,

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

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

Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

Re: Sorting text file content with batch script,.

#4 Post by Rajnishjc_27 » 10 Sep 2019 23:40

Please Help on this.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Sorting text file content with batch script,.

#5 Post by penpen » 11 Sep 2019 02:01

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

Rajnishjc_27
Posts: 21
Joined: 16 Aug 2019 23:35

Re: Sorting text file content with batch script,.

#6 Post by Rajnishjc_27 » 12 Sep 2019 00:58

Thank you so much PenPen for your kind help.

Post Reply