Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi ,
I have a string as WindowsXP-KB959542-Today.exe which need to be parsed to get only KB959542 . Can any one please help me in parsing this string in a batch file..Its Urgent plz

Thanks a bunch...
Can you suggest me what i need to change in the script.. if such strings( WindowsXP-KB959542-Today.exe) are there in a .txt file in each line...
Thanks...

vbscript
Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "c:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine s = Split(strLine,"-") WScript.Echo s(1) Loop objFile.Closesave as myscript.vbs and on command line
c:\test> cscript /nologo myscript.vbs

"Can you please also help me in storing the for loop value each time in a variable .."
Perhaps this is what your after:
setlocal enabledelayedexpansion for /f "usebackq tokens=2 delims=-" %%a in ("your text file") do ( set /a cnt+=1 set var!cnt!=%%a )

Thanks for your timely help!!
I need one more suggestion in following problem..plz help me out!!
There are two text files with five lines each. I want to read both text files and have first line from one file and first line from second test file ..do some operation...then again second line from one file and second line form second file. and do operattion...so on uptill 5 lines...
Please help me in this....as i am new to batch file creation...Thanks in advance..

Reading multiple files concurrently is problematic in batch files, it is possible but takes a lot of mucking around. Blank lines can also be a problem..
Here's a quick job, it's quite inefficient(and a bit of an abuse of find and findstr..) but seems to work......
for /f %%a in ('type "file1"^|find /c /v ""') do set /a size=%%a for /l %%a in (1,1, %size%) do ( for /f "tokens=2 delims=-" %%b in ('type "file1"^|find /n /v "" ^|findstr /b /l "[%%a]"') do ( for /f "tokens=2 delims=-" %%c in ('type "file2"^|find /n /v "" ^|findstr /b /l "[%%a]"') do ( echo %%b --- %%c ) ) )This code Assumes:
1. That both files have the same number of lines.
2. Both files contain the same type of data.
3. That there is no blank lines.
On a side note, you should show a little more initiative than just ask for someone to code it for you, the net is jam pack with examples and reference material.....

Thanks for suggestion....But I am really new to the batch scripting....
Anyways..I have checked for my data..it is not working as it has data in each line and two text files are seperate
Atlast help me with one thing...can we delete a line in a text file thru for loop..i searched..but no where i found the help...
Hoping you will help me...Judago!!

Anyways..I have checked for my data..it is not working as it has data in each line and two text files are seperate
Atlast help me with one thing...can we delete a line in a text file thru for loop..i searched..but no where i found the help...
The Code I posted in #9 does run over two files("file1" and "file2"), albeit inefficiently and in very limited scope.
To delete a line you have to run a for loop over the file, exclude the unwanted line, output to a new file the delete the old file and rename the new file or move the new file over the top of it.
This should work to exclude a line by line number(blank lines will cause an issue).
set cnt= set exclude=8 for /f "usebackq delims=" %%a in ("your file") do ( set /a line+=1 for /f %%b in ('call echo %%line%%') do ( if not %%b==%exclude% ( >> newfile echo %%a ) ) ) move "%cd%\newfile" "%cd%\yourfile"

![]() |
![]() |
![]() |

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