1.

Solve : Find text in file?

Answer»

I have searched the forums, and found several instances of using FOR in a batch file to read lines of text from a text file... what I need is to read a specific portion of a line of text. Basically, I'm writing a script that will get the version of the current bios, so that I can then automate updating the BIOS.

So, given the following text file:
Code: [Select]Program: eSupport.com BIOS Detect v1.2 July 21, 2003
BIOS Date: 12/02/04
BIOS Type: Phoenix - AwardBIOS v6.00PG
BIOS ID: 12/02/2004-CLE266-8235-6A6LUAKCC-00
OEM Sign-On: **** POD-6717 BIOS V1.10c (04/24/2008) ****
Chipset: VIA 82C3123 rev 0
Superio: Winbond 697HF rev 2 found at port 4Eh
CPU Type: Intel Celeron(R)
CPU Speed: 650 Mhz
CPU Max: 1500 Mhz
BIOS ROM In Socket: YES
BIOS ROM Size: 256K
Memory Installed: 1024 MB
Memory Maximum: 768 MB

eSupport.com, Inc.
1-800-800-BIOS (2467)
www.esupport.com
Where the line containing "OEM Sign-On:" contains the version information I am looking for, I would like to retrieve just the "V1.10c" portion of the string and evaluate it.
Other version NUMBERS that we may come across include V1.11, V1.14, and V1.10. OBVIOUSLY, I would need a way to also handle the instance where V1.10c includes an extra character. Once I can evaluate this, then I can move within my batch file to install the correct update to the bios.

Thanks in advance! @echo off
set file=bios-text.txt
for /f "tokens=1,2,3,4,5,6 delims= " %%a in ('type %file% ^| find "OEM Sign-On"') do set version=%%f
echo BIOS version appears to be %version%

Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject")
strMyFile = "C:\test\bios.txt"
Set objFile = objFS.OpenTextFile(strMyFile)
Do Until objFile.AtEndOfLine
strLine = objFile.ReadLine
If InStr(1,strLine,"OEM") Then
ArrR = SPLIT(strLine," ")
For i = LBound(ArrR) To UBound(ArrR)
If Mid(ArrR(i),1,1) = "V" Then
WScript.Echo ArrR(i)
End If
Next
End If
Loop
save the above as script.vbs and on command line
Code: [Select]c:\test> cscript /nologo script.vbs
V1.10c
hi all
i think this will do it
for /f "tokens=1,2,6 " %%i in (filename) do (if '%%i' EQU 'OEM' if '%%j' EQU 'Sign^-On:' echo %%k)

am I wrong if so kindly explain for me .
have you tried it out?
yes well then



Discussion

No Comment Found