Edit txt file by bat

Asked

Viewed 3,356 times

1

I have the following problem: In a Windows directory, I have 3 files .txt that every day is created automatically. Within them there are several lines with information. I wish to erase two lines that always repeat in all .txt and then save them without those two lines, continuing in the same directory.

You could do that automatically with a .bat, a script or something that can be automated? If yes, how can I do?

  • Are these two lines always at the beginning or end of the file? or does it vary?

  • 1

    Always the second and fourth line, within the . txt

1 answer

1

Thus :

@echo off
setlocal enabledelayedexpansion

for %%x in (*.txt) do (
        call:skip "%%x"
        )
exit/b

:skip

set/a $c=1

(for /f "delims=" %%a in (%~1) do (
  if not !$c!==2 if not !$c!==4 echo %%a
  set /a $c+=1))>out.txt

move out.txt %1 2>nul

Browser other questions tagged

You are not signed in. Login or sign up in order to post.