batch file - Almost there... Need to find and replace. Using for loop -


I am trying to find and replace. I'm using one for loop, I'm learning, but I'm almost there. I have tried to find the answer but the formulas are very misleading to me.

Delim is an empty space and as you can tell that I'm leaving 4 lines and the second is token.

I have been replaced by the place var5a where I need it backwards, as I %% F Requires the same var5a , not the other way (as I've just written down). But do not know how to write please tell me how to do it. I & lt; & Lt; Tried to use =, but no fate.

 for  skip = 4 tokens = 2 delims = "%% F in (script.vbs) (Set Var5a =! Var5a! %% F)   

I'm learning please be kind.

  @ECHO OFF SETLOCAL :: Replace the file with line 5 of the token 2 (location Replace different): Assume that the file exists, etc. And no line started "SET" replacement = this replacement text del newfile.txt 2 & gt; Nul FOR / f "token = 1 * delims =:" %% i IN ('findstr / n / r "$" ^ oldfile.txt') is DO (IF %% i == 5 (FOR / f "Tokens = 1,2 * delims =" %% l IN ("%% j") DO & gt; newfile.txt ECOSH %% L% replacement% %% N) ELSE (& gt; newfile.txt. ECHO.% % J)) TYPE oldfile.txt ECHO ==== Separator ====== FC Old File. Txt newfile.txt   

Result:

  line one should not be changed line 2 should not be changed line 3 should not be changed line four Should not be replaced changeme iwillbereplaced but only on this line and notbere was placed on previous lines including the previous row which was empty ==== Separator ======= Compare files oldfile.txt and NEWFILE.TXT * **** oldfile.txt should not be changed to line four Iwillbereplaced but only changes on this line and Notary on Prahlad lines. ***** NEWFILE.TXT line four should not be changed This is the text of the change, but there is no notary on this line and on the lines of the next *****   

It has difficulties - especially if the lines of your file begin with a colon or the quoted string or % / P> So - after all I have done what you are doing. You have omitted important information that the string in %% F is not cited only, it also has an empty space.

Did you say that in the first place, you have more hours in your project, and I am rich with a handful of aspirin.

To load% F with the quoted string, I read a string from a file. @ECHO OFF SETLOCAL Enabled Expansion :: Replace Token 2 (different from location) in line 5 of a file with replacement: file exists, and suppose any row Not started ":" SET Replacement = "This Copy Text" DEL newfile.txt 2 & gt; NUL :: iwbr.txt is included in the following: To load F% in% i%, the "I will be replaced" :: on line will be replaced by FOR / f for "Delims =" %% F IN (iwbr.txt) DO (FOR / f "tokens = 1 * delims =:" %% i IN ('findstr / n / r "$" ^

Result:

  The line should not be changed Line two should not be changed Line three should not be replaced by "changed" line Changes to the four should not be changed "I will be transferred" but do not ignore the previous lines on this line and empty space with the "previous" line "unbalanced-bid line ... = === separator ==== === Compare files oldfile.txt and NEWFILE.TXT ***** oldfile.txt Change the line four will not be changed Should not "I have a beerplouse" but will not just leave this line on the lines and the later ***** NEWFILE.TXT line four should not be changed, the change is "This is the replacement text", but only on this line and after Lines will not be ignored *****    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -