Batch insert empty lines
Solved
jopoiss
Posted messages
104
Status
Membre
-
mimi -
mimi -
Hello,
I would like to know how to insert blank lines into a text file with a *.bat when a specific word is detected.
In other words, I want my batch file to detect a specific word, and when it sees it, insert a blank line afterward. I specify that the word I want to detect will always be at the end of the line.
I think an if statement is needed, but I am a beginner in this area, so I need your help.
Thank you in advance.
I would like to know how to insert blank lines into a text file with a *.bat when a specific word is detected.
In other words, I want my batch file to detect a specific word, and when it sees it, insert a blank line afterward. I specify that the word I want to detect will always be at the end of the line.
I think an if statement is needed, but I am a beginner in this area, so I need your help.
Thank you in advance.
Configuration: Windows XP Opera 9.27
6 réponses
Hello,
Try this, I hope it meets your expectations!
To activate the batch, you enter its name in the command prompt followed by the string to locate.
--
Best regards.
Cchristian.
Try this, I hope it meets your expectations!
To activate the batch, you enter its name in the command prompt followed by the string to locate.
@SETLOCAL ENABLEDELAYEDEXPANSION MODE CON COLS=150 LINES=90 ECHO OFF CLS ECHO. ECHO. ECHO %0. ECHO. FOR /L %%I IN (3,-1,0) DO @echo. ECHO _________________________________________________ ECHO. ECHO %0 %1 %2 The %DATE% at %TIME% ECHO _________________________________________________ ECHO. TITLE %0 STRING SEARCH AND INSERTION OF BLANK LINES CD C:\Documents and Settings\christian\My Documents\BATCH_files rem input file containing the text to analyze. SET "testIN_txt=%USERNAME%-testIN.txt" rem intermediate working files SET "testINT_txt=%USERNAME%-testINT.txt" SET "testINTB_txt=%USERNAME%-testINTB.txt" IF EXIST %testINT_txt% ( ERASE /A %testINT_txt%) IF EXIST %testINTB_txt% ( ERASE /A %testINTB_txt%) rem Numbering the lines of text from the INPUT file. SET /A "calcul=10001" FOR /F "tokens=1-1* delims=$" %%I in ( %testIN_txt% ) DO ( ECHO !calcul!#%%I >> %testINT_txt% SET /A "calcul=calcul+10" ) rem -Search in the file for the string to locate SET "loc_chaine=%1" FOR /F "tokens=1,1 delims=:#" %%I IN ( ' TYPE %testINT_txt% ^| FINDSTR /I %loc_chaine%' ) DO ( SET /A "calcul=%%I+1" ECHO !calcul!# blank line to insert >> %testINT_txt% ) rem -Sort the lines of the intermediate file to merge them. SORT /+1 /M 1024 /REC 256 %testINT_txt% /O %testINTB_txt% rem I deliberately did not recreate the original file testIN_txt for rem precaution, it's up to you to see! ERASE /A %testINT_txt% rem -Elimination of the generic part of each line (numbering rem and delimiter #) from the new file. FOR /F "tokens=2,3* delims=#" %%i in ( %testINTB_txt% ) DO ( rem display on screen for test ECHO %%i%%j %testINT_txt% ECHO %%i%%j >> %testINT_txt% )
--
Best regards.
Cchristian.
That's good, I figured it out myself with an if statement involved in a for loop.
But thank you anyway for looking into my problem.
Have a nice day.
But thank you anyway for looking into my problem.
Have a nice day.