Computing.Net > Forums > Programming > Batch Sort List

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Batch Sort List

Reply to Message Icon

Original Message
Name: stroke6463
Date: February 7, 2006 at 12:09:35 Pacific
Subject: Batch Sort List
OS: XP Pro
CPU/Ram: idk
Comment:

I need help with a batch. I have a text file that is sorted something like this.

Add
Apple
Bear
Cat
Wow
Xenon
Quiet
List

Is there anyway to way to make it that when the next letter is out of alphabetical sequence it will remove the remainder of the text file. So "Quiet" and "List" would be deleted because they are not greater than X. I would like to know how to do it in a batch file, if it even is possible. Thanks.


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: February 7, 2006 at 13:46:35 Pacific
Reply:

The following batch does that

@Echo Off > %~pn1.out
Set FOut=%~pn1.out
Set PrevChar=~
For /f "tokens=* delims=" %%I in (%1) Do ( Call :SCREEN %%I)
Set PrevChar=
Set Char=
Set FOut=
GoTo :EOF

:SCREEN
Set Char=%1
Set Char=%Char:~0,1%
If "%Char%" lss "%PrevChar%" GoTo :EOF
Echo %*>> %FOut%
Set PrevChar=%Char:~0,1%
GoTo :EOF

To run type at prompt Screen FileName (assuming the batch was stored as Screen.bat) and you get the filtered file in FileName.out.

That works under Win NT/2K/XP only not 9X/ME and if you want to delete only the lines out of sequence and not the remainder of the file post again as the script needs to be adjusted.


Report Offensive Follow Up For Removal

Response Number 2
Name: IVO
Date: February 7, 2006 at 13:49:27 Pacific
Reply:

Please, note that the For /F statement fits just ONE line starting with For and ending with %%I) without CR/LF between Do and (Call.


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: February 7, 2006 at 21:44:01 Pacific
Reply:

IVO,

You're the man.


If at first you don't succeed, you're about average.

M2Go


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home



Results for: Batch Sort List

List traverse, batch (NT)
    Summary: Hey again.. I hopefully found a much more efficient way or finding duplicates in the list.. No need for parsing anymore, which wouldnt work anyways, since some numbers in the list are longer than the ...
www.computing.net/answers/programming/list-traverse-batch-nt/12910.html

Batch to move file by sysdate
    Summary: AngusYoung, You're with ACDC, right? [1] perl is for any regex job. FM is the man to see. [2] How did you get the BATCH sorted out? ===================================== If at first you don't succe...
www.computing.net/answers/programming/batch-to-move-file-by-sysdate/14939.html

DOS - batch variables
    Summary: <blockquote> Response Number 1 Name: Mechanix2Go Date: February 07, 2007 at 13:27:02 Pacific Homepage: Golden-Triangle Subject: DOS - batch variables Reply: To test for equality: if %SDC%==0 Th...
www.computing.net/answers/programming/dos-batch-variables/15058.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History






Data Recovery Software