June 8, 201115 yr There are two files:1.txt[SourceFileInfo]clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,555682.txt[SourceFileInfo]clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760If I do "copy 1.txt+2.txt 3.txt" I get this:[SourceFileInfo]clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568[SourceFileInfo]clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760but I would like to get something similar to this:[SourceFileInfo]clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760Is it possible?
June 8, 201115 yr sort 3.txt /o 4.txtOne liner (but needs fixing by someone more knoledgable):copy 1.txt+2.txt | sort /o 3.txtGL
June 8, 201115 yr Or using unix tools:grep -vi "\[SourceFileInfo\]" 1.txt >>2.txt"\" are need to escape the "[" used with grep for regular expression.
June 8, 201115 yr Author Thank you very much I'll check them for sure. I'm especially interested in this unix one as it could be used in a batch script.By the way, could anyone help me with this script?MD HFMER TEMP2DIR/B/A-D/OGN/ON HF\*.EXE>HF.TXTSET HF=FOR /F %%I IN (HF.TXT) DO (SET HF=%%I&IF DEFINED HF CALL :HFEXTRACT)DEL/Q/S HF.TXTREM ======================TYPE 1 HOTFIXES=================================================:HFEXTRACTTITLE %T1% - Processing %HF%ECHO %HF%MD TEMP&START/WAIT HF\%HF% /Q /X:TEMPXCOPY/DEHRY TEMP HFMERMOVE TEMP\UPDATE\update.inf HFMER\UPDATE\%HF%.infMOVE TEMP\UPDATE\update_w2k.inf HFMER\UPDATE\%HF%.infMOVE TEMP\UPDATE\update.ver TEMP2\%HF%.verDEL/Q/S HFMER\UPDATE\update*.inf HFMER\UPDATE\update.verRD/Q/S TEMPCLSREM =====================================================================================COPY/B TEMP2\*.ver HFMER\UPDATE\update.verSORT HFMER\UPDATE\update.ver /O HFMER\UPDATE\update.verRD/Q/S TEMP2This is a mix of strings taken from HFSLIP and my own but the problem is that I need the last three lines to go after the rest of the script is finished. It work correctly if I remove the last line but the folder TEMP2 is not deleted then. Edited June 8, 201115 yr by tomasz86
June 8, 201115 yr Author I've managed to overcome it:IF EXIST HF\*.EXE ( MD HFMER TEMP2 DIR/B/A-D/OGN/ON HF\*.EXE>HF.TXT SET HF= FOR /F %%I IN (HF.TXT) DO (SET HF=%%I&IF DEFINED HF CALL :HFEXTRACT) DEL/Q/S HF.TXT CALL :HFCS)REM ======================TYPE 1 HOTFIXES=================================================:HFEXTRACTTITLE %T1% - Processing %HF%ECHO %HF%MD TEMP&START/WAIT HF\%HF% /Q /X:TEMPXCOPY/DEHRY TEMP HFMERMOVE TEMP\UPDATE\update.inf HFMER\UPDATE\%HF%.infMOVE TEMP\UPDATE\update_w2k.inf HFMER\UPDATE\%HF%.infMOVE TEMP\UPDATE\update.ver TEMP2\%HF%.verDEL/Q/S HFMER\UPDATE\update*.inf HFMER\UPDATE\update.verRD/Q/S TEMPIF NOT EXIST HF.TXT ( COPY/B TEMP2\*.ver HFMER\UPDATE\update.ver SORT HFMER\UPDATE\update.ver /O HFMER\UPDATE\update.ver RD/Q/S TEMP2)REM ======================================================================================I have a question about this Unix tool called grep.When I have only two files:1.ver[SourceFileInfo]basesrv.dll=7F87C84D34813197A2360CEA800A7464,0005000008931B27,46352cmd.exe=7705AED861C7FDBD919E771A1B42B5AA,0005000008931AA8,2363042.ver[SourceFileInfo]clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760after "grep -vi "\[sourceFileInfo\]" 1.ver >>2.ver"[SourceFileInfo]clusapi.dll=B95AC82B54FE4359C3453264F848509A,0005000008931AA8,55568clusnet.sys=A0610690266ED57A2D04EA5D7EC8084C,0005000008931AA8,67760basesrv.dll=7F87C84D34813197A2360CEA800A7464,0005000008931B27,46352cmd.exe=7705AED861C7FDBD919E771A1B42B5AA,0005000008931AA8,236304Everything is OK. What about more than two files? Is it possible to use grep with multiple files?Also an another question (2 questions ): Can the list be sorted alphabetically? Is there a way to remove duplicates? Edited June 8, 201115 yr by tomasz86
June 8, 201115 yr Yes grep can work on multiple files and no it can't sort or remove duplicates unless you do the scripting for it .
June 9, 201115 yr Author How should I use this commandgrep -vi "\[SourceFileInfo\]" 1.txt >>2.txtwhen there are multiple files?I tried something like this:grep -vi "\[SourceFileInfo\]" *.txt >>3.txtbut it doesn't work. Also tried doingcopy 1.txt+2.txt 3.txtgrep -vi "\[SourceFileInfo\]" 3.txt >>3.txtbut after doing this there is no longer [sourceFileInfo] in the final file. Edited June 9, 201115 yr by tomasz86
June 9, 201115 yr grep -vih "\[SourceFileInfo\]" 1.txt 2.txt >>3.txtBut then if you need sorting and finding duplicates to choose the most recent version of each file, you might want to use vbs or autoit as it would be a lot more easier to script. Edited June 9, 201115 yr by allen2
June 9, 201115 yr Author I see. Any way to do it for a larger number of files automatically, ex. 50 text files in one directory?
June 9, 201115 yr Yes something like this should work (i added the sort part with the unix tool "sort.exe") :set filenames=for /f "delims= usebackq" %%i in (`dir /b %target%\*.inf`) do (set %filenames%=%filenames% %%i)echo [SourceFileInfo] >result.txtgrep -vih "\[SourceFileInfo\]" %filenames% |sort -d >>result.txtDue to batch variables limitations %filenames% can't have more than 2047 characters so it might not work with long filenames. Edited June 9, 201115 yr by allen2
June 9, 201115 yr Author It's getting a little bit complicated for me as I'm just a beginner when it comes to scripting Anyway, I'll try to get the above script to work.
June 9, 201115 yr @allen2You don't actually *need* grep or any other "third party" program for such a simple task.You can use either FIND /V "[" to exclude the line(s) containing square brackets or or use a FOR /F with a SKIP=1 (if that line is always the first one), or use FIND or FINDSTR to only get lines containing commas.This could do:@ECHO OFFIF EXIST result.txt DEL result.txtFOR /F %%A IN ('dir /b *.txt') DO (FOR /F "skip=1 tokens=*" %%B IN (%%A) DO (ECHO %%A -- %%BECHO %%B >>lines.txt))ECHO [SourceFileInfo] >result.txtSORT lines.txt >>result.txtDEL lines.txtECHO.MORE result.txtjaclaz
June 9, 201115 yr @jaclazI hate the dos find because i always had hard time getting it to do what i wanted ; and also, as i began scripting on unix , i always find first an algorithm translation with a batch adapted from some kind of unix shell scripting.Anyway, i never said my script coding was the best or even good.That said, i would do what tomasz86 is trying to do (extracting hotfix, getting files with the higher version in one .inf to create a service pack) with autoit (for the duplicate file part) but a batch script might be easy for you.
June 9, 201115 yr Author Thank you very much I changed it like this:@ECHO OFFFOR /F %%A IN ('dir /b *.ver') DO (FOR /F "skip=1 tokens=*" %%B IN (%%A) DO (ECHO %%A -- %%BECHO %%B >>TEMP2\update.txt))ECHO [SourceFileInfo] >HFMER\UPDATE\update.verSORT TEMP2\update.txt >>HFMER\UPDATE\update.verDEL TEMP2\update.txtECHO.MORE HFMER\UPDATE\update.verbut I can't set the folder for '*.ver' files to be 'TEMP2\*.ver'. How should I edit this line?FOR /F %%A IN ('dir /b *.ver') DO ( Edited June 9, 201115 yr by tomasz86
Create an account or sign in to comment