Batch insert empty lines

Solved
jopoiss Posted messages 104 Status Membre -  
 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.
Configuration: Windows XP Opera 9.27

6 réponses

cchristian Posted messages 928 Status Membre 131
 
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.

 @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.
2
jopoiss Posted messages 104 Status Membre 17
 
Re, no one can help me?
0
jopoiss Posted messages 104 Status Membre 17
 
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.
0
cchristian Posted messages 928 Status Membre 131
 
Thank you for the feedback. Can you post your solution?
--
Best regards.

Christian.
0
jopoiss Posted messages 104 Status Membre 17
 
FOR /f "tokens=1-10" %%a IN (temp4.txt) DO (
if %%e EQU in ( echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j
echo.
echo. ) else ( echo %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j )
) >> "ACL switch L3 modifi‘ prêt.txt"
erase temp4.txt

Voilà. Have a nice day.
0
mimi
 
Hello,
Can you comment on your lines please?
Thanks in advance
0
cchristian Posted messages 928 Status Membre 131
 
Good evening,

Thank you, it's too much for me, I didn't understand,
--
Best regards.

Cchristian.
0