Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Find text in file  (Read 3129 times)

0 Members and 1 Guest are viewing this topic.

wolfpackmars2

  • Guest
Find text in file
« on: April 25, 2008, 09:53:21 AM »
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!

Dias de verano

  • Guest
Re: Find text in file
« Reply #1 on: April 25, 2008, 11:24:34 AM »
@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%


ghostdog74



    Specialist

    Thanked: 27
    Re: Find text in file
    « Reply #2 on: April 25, 2008, 10:43:25 PM »
    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

    .bat_man

    • Guest
    Re: Find text in file
    « Reply #3 on: April 29, 2008, 04:30:17 AM »
    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 .

    Dias de verano

    • Guest
    Re: Find text in file
    « Reply #4 on: April 29, 2008, 04:42:00 AM »
    have you tried it out?

    .bat_man

    • Guest
    Re: Find text in file
    « Reply #5 on: April 29, 2008, 04:43:40 AM »
    yes

    Dias de verano

    • Guest
    Re: Find text in file
    « Reply #6 on: April 29, 2008, 04:48:20 AM »
    well then