Computing.Net > Forums > Programming > Batch Sort List

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Sort List

Reply to Message Icon

Name: stroke6463
Date: February 7, 2006 at 12:09:35 Pacific
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.



Sponsored Link
Ads by Google

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.


0

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.


0

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


ADO.Net MSDE connection p... Extract First Line of Tex...



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


Sponsored links

Ads by Google


Results for: Batch Sort List

List traverse, batch (NT) www.computing.net/answers/programming/list-traverse-batch-nt/12910.html

Batch dir list then txt edit it..? www.computing.net/answers/programming/batch-dir-list-then-txt-edit-it/18773.html

Batch to move file by sysdate www.computing.net/answers/programming/batch-to-move-file-by-sysdate/14939.html