1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch file issues

Discussion in 'DOS/Other' started by lammv, Aug 30, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. lammv

    lammv Thread Starter

    Joined:
    Aug 18, 2012
    Messages:
    10
    Hello there.
    I 'm trying to solve one issue.

    1. I have a file names.ini. The end of the file is:

    Code:
    FOV=15
    [Network] 
    Networkline=default
    Here I need to change FOV and two last lines leave the same. So I use the FINDSTR.
    The easiest way for me is finding lines which contain words " network fov", delete them and then add to the file following lines


    Code:
    echo FOV=%m% >> names.ini
    echo [Network] >> names.ini
    echo Networkline=default >> names.ini
    so. FIND and DELETE.

    I've found how to FIND

    Code:
    sc query | findstr /i "network fov" names.ini  ?????
    how to delete the founded lines?

    2. And for sure.
    what is the command here just replacing FOV with its new value

    Code:
    sc query | findstr  "FOV" names.ini  ?????
    how to replace the founded line by the new FOV's value?
    3. Also I have a line in the names.ini file
    NAME=changed_username

    I can find it by means of the line too.
    But how can I read it and use it in my next operations?


    Code:
    sc query | findstr "FOV" names.ini   ????
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Well your syntax isn't even close if you were using quarter stick of TNT to try and accomplish this task.

    Let me see the output of
    Code:
    sc query | findstr /C:"FOV"
     
  3. lammv

    lammv Thread Starter

    Joined:
    Aug 18, 2012
    Messages:
    10
    Can you be more specific, because the issue doesn't work so far.
    I brought up 3 questions.
    Can I get back 3 lines of your answers?
    Thank you.
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    I can't answer any of your questions until you show me the output of
    Code:
    sc query | findstr /C:"FOV"
    From what I understand you are trying to update the "names.ini" file with output from the "SC QUERY" command.

    If you cannot answer my questions then I cannot answer yours.
     
  5. bliss-II

    bliss-II

    Joined:
    Oct 18, 2012
    Messages:
    33
    Code:
    sc query | findstr /c:"FOV" >> tempfile
    for /f "skip=1 tokens=1" %%a in (names.ini) do echo %%a >> tempfile
    del names.ini
    ren tempfile names.ini
    The FOR loop basically skips the first line and dumps the rest into tempfile.

    The rest should be self-explanatory.
     
  6. foxidrive

    foxidrive

    Joined:
    Oct 20, 2012
    Messages:
    728
    This should do it too and uses GNUsed for Windows.

    It expects that FOV=NNN only appears once in the output from SC query and it is designed to replace the entire line when FOV= appears in the first column of names.ini

    I can't check the format of FOV=NNN from sc query as it doesn't appear on my machine.

    Code:
    @echo off
    for /f "delims=" %%a in ('sc query ^| findstr /c:"FOV"') do (
    sed "s/^fov=.*$/%%a/I" names.ini >names.ini.tmp
    )
    move /y names.ini.tmp names.ini
    Thanks to squashman for pointing out the forum - another one for me to play in. ;)
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1067089