Delete/Skip particular lines or value in txt file RRS feed

  • General discussion

  • @echo off & setlocal enabledelayedexpansion
    set e=
    set /p e=char. set:
    if not defined e goto :eof
    set ee=
    set r=0
    call :xx %e%
    set /a len=r-1
    set r=
    set e=%ee%
    if not defined e goto :eof
    set q=0
    set /p q=length of output string:
    if q lss 1 goto :eof
    :: q needs to be adjusted to one less than what you really want, so...
    set /a q-=1
    >>strings echo ======= %~n0.bat =========
    call :aa
    goto :eof
    @echo off & setlocal
    @set z=%1
    @for /L %%a in (0,1,%len%) do @(
    @rem these next 8 at-signs are not really necessary, but I put them anyway.
    @set zz=%z%!e:~%%a,1!
    @call :xx !zz!
    @if !p! leq %q% @(
    @call :aa !zz!
    ) else @(
    @>> strings.txt echo %z%
    @goto :eof
    goto :eof
    @echo off
    @set p=0
    @set xx=%1
    @set x=!xx:~%p%,1!
    @if "!x!" equ "" goto :xit
    :: all this block had to be added to filter the original input char.s
    @if defined r (
    set test=!ee!
    if defined ee set ee=!ee:%x%=!
    if "!ee!" equ "!test!" (
    set /a r+=1
    set ee=!ee!%x%
    ) else (
    set ee=!test!
    @set /a p+=1
    @goto :x1
    @set /a p-=1

    :::::::::::::: HERE IS THE OUTPUT OF ABOVE CODE ::::::::::::::::::::



    As mention above batch file is creating new text file and generating these values as mentioned above in output, everything is fine but i need stop those value which contains "aa" , such as when aab is going to save in txt file before saving it i need mark one check point if any value contain "aa" so it skip/delete this entire value and proceed further as normal output.

    aaa  (Skip this line)
    aab  (Skip this line)  
    aac  (Skip this line)
    bbc  (print this line)
    cbc  (print this line)
    cca  (print this line)
    ccb  (print this line)

    • Changed type Bill_Stewart Monday, April 30, 2018 9:25 PM
    • Moved by Bill_Stewart Monday, April 30, 2018 9:26 PM Batch files are obsolete
    Friday, February 23, 2018 7:47 PM

All replies

  • You will be much better off using PowerShell. Cmd.exe shell scripts (batch files) are very arcane and hard to troubleshoot.

    -- Bill Stewart [Bill_Stewart]

    Friday, February 23, 2018 7:57 PM