Hajas
Hajas

Reputation: 87

Process each line which contains a string in several files (Windows Batch)

I'm already very close of what I want and the script runs fine if the files are clean ONLY, but most of them have several comments, few of them inside /* ... */ blocks aside other crap that need to be deleted.

So I just want to process the lines which have the string level.waypoints

Here what I have now:

@echo off
setlocal enableDelayedExpansion

set findtext="level.waypoints"
for %%F in (*.gsc) do (
  set "out="
  set "i=x"
  > "%%~nF.cfg" (
    for /f usebackq^ tokens^=2^,4^,5^ delims^=[]^=(^)^;^"^  %%A in ("%%F") do (
      if %%A neq !i! (
        if defined out echo !out!"
        set /a "i=%%A, j=0"
        set "out=set flwp_!i! "!i!"

      ) else (
        set /a j+=1
        if !j! leq 3 (set "out=!out!,%%B") else set "out=!out!,%%C"
      )

    )
    if defined out echo !out!"
    set /a "fim=i+1"
    echo set flwp_!fim! "eof"
  )
)

I was thinking in add findstr %findtext% into these loops but I tryed in many different ways, but didn't succeed yet sadly... Could you help me?

thank you very much!

Upvotes: 0

Views: 140

Answers (1)

SachaDee
SachaDee

Reputation: 9545

If you just want to delete the lines of each .gsc file containing the string level.waypoints

@echo off 
set "findtext=level.waypoints"

for %%a in (*.gsc) do (
    for /f "delims=" %%b in ('type "%%a"') do (
       echo %%b | find /i "%findtext%" >nul || echo %%b >>"%%~na_New%%~xa"
     )
    move "%%~na_New%%~xa" "%%a" 2>nul
)

Upvotes: 1

Related Questions