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
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.
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.
Summary: I did something similar several years ago to get rid of duplicate lines. First I sorted: sort < list.txt > list.sor Then the BAT looked at the first line, set a var; looked at the second line, set ...
Summary: Ok hi all, is it possible to list a dirs contents then write that to a text file and put each item in the list into information. So say the dir has 100 zip files 123.zip abc.zip etc, it woulod list th...
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...