| 1. |
Solve : Using the FOR command? |
|
Answer» Hello, with just ten lines of code more or less. How about one? command does "that sort of thing" very well. It was designed for it. It LOVES chewing up csv files. Took me 7 minutes. And 5 of those I was MAKING coffee. Presuming the answer to my question above is "yes"... Code: [Select]@echo off set inputfile=input.txt set outputfile=output.txt if exist "%outputfile%" del "%outputfile%" for /f "tokens=1-2* delims=," %%A in ( ' type "%inputfile%" ' ) do echo %%~nxB>>"%outputfile%" input.txt: Code: [Select]00000,,\6442\Vol002\001\00000.tif,Y,,,0 000001,,\6442\Vol003\001\002\000001.tif,Y,,,0 000002,,\6442\Vol003\001\000002.TIF,Y,,,0 000003,,\6442\Vol003\005\004\000003.TIF,,,, output.txt: Code: [Select]00000.tif 000001.tif 000002.TIF 000003.TIF AAwwkk ! I have a headache! It took your 7 Mins. It will take me 7 days to try and understand that! for /f TREAT the dataset (what is in the brackets) as a series of one or more lines "tokens=1-2* delims=," Treat each such line as being split (by commas) into at least 2 tokens (chunks) %%A Assign the first chunk of each line to the explicit loop variable %%A. The second chunk will therefore be the implicit loop variable %%B. The asterisk in the tokens/delims block means that all of the rest of the line (if there is any) will be the implicit loop variable %%C. in ( ' type "%inputfile%" ' ) The dataset is the output of 'type inputfile'. do echo %%~nxB Take the second chunk of the line, (a path and filename), and extract just the file name and extension, and echo it... >>"%outputfile%" ... to the output file and repeat until no more lines left. Quote from: Geek-9pm on February 02, 2009, 03:27:52 PM If it's any help, that's what Perl does to me. Dias DE verano, Yes you are right on your first assumption. I will put it to the test on a very large file that I have. I very much appreciate your speedy reply to my post today. thatguy.It works great. Sorry for the confusion. Thanks so much! |
|