Announcement

Collapse
No announcement yet.

Batch file to filter and rename string in txt file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch file to filter and rename string in txt file

    hello all

    I have such problem with creation of bat.file ( Windows version 5.2.3790 )

    In txt file I have strings like :
    Code:
    Displaying status for license file: <server>
    
                           License    In Use   Free
                           -------    ------   ----
                  Mechanism            0       7
             
                FoundationAdv          0      1
             SSILINKCLIENT_License       1       3              
              ILINK_CLIENT_License       2      1
    by filter to find only SSILINKCLIENT_License and ILINK_CLIENT_License + values of free
    Code:
    @Echo off
    
    
    
    set PATH=%PTC_HOME_DRIVE%\users\%USERNAME%
    setlocal enableextensions enabledelayedexpansion
    
    for /f "tokens=1,3" %%a in ('type %PATH%\report.txt') do (
        if "x%%a"=="xSSILINKCLIENT_License" (
    
            echo %%a %%b >> "%PATH%\status.txt"
        )
        if "x%%a"=="xILINK_CLIENT_License" (
            echo %%a %%b >> "%PATH%\status.txt"
        )
    )
    endlocal
    and I have
    SSILINKCLIENT_Licese 3
    ILINK_CLIENT_License 1

    question is how to rename this SSILINKCLIENT_License to TAG and ILINK_CLIENT to Engineers ? integer values without changes.

    thanks and regards
    Last edited by Rems; 1st July 2010, 21:19.

  • #2
    Re: Batch file to filter and rename string in txt file

    Note that the variable Path you defined in the batch is also a system variable. When you overwite its value the script is not able to locate files like find.exe and findstr.exe any more.


    Code:
    @Echo off
    
    
    setlocal enableextensions enabledelayedexpansion
    
    set $PATH=%PTC_HOME_DRIVE%\users\%USERNAME%
    
    for /f "tokens=1,3" %%a in (
       'Findstr.exe /ic:"SSILINKCLIENT_License" /ic:"ILINK_CLIENT_License" "%$PATH%\report.txt"') do (
       Set str=%%a
       Set str=!str:SSILINKCLIENT_License=TAG!
       Set str=!str:ILINK_CliENT=Engineers!
       >> "%$PATH%\status.txt" echo.!str! %%b
    )
    endlocal
    \Rems

    [Edit] After having a closer look at the txt file, I changed 'Findstr.exe /bic: ...' into 'Findstr.exe /ic: ...'
    Last edited by Rems; 1st July 2010, 21:24.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Batch file to filter and rename string in txt file

      wow great it works perfectly . thank you for you help.

      best regards

      Comment

      Working...
      X