Solved Insert blank line before a certain character

April 8, 2013 at 01:31:29
Specs: Windows XP
Hi all

Can anybody tell me if the following problem can be solved with a batch file (XP)?
I have a text-file (*.txt) with several lines. Everytime a certain character appears (it appears always at the beginning of a line and in the example below it is the character "%") I would like to insert a blank line before it. For instance:

Before:
This is my text and everytime this
% character appears I would like to insert a blank line before it.

After:
This is my text and everytime this

% character appears I would like to insert a blank line.

Thank you very much for your help!


See More: Insert blank line before a certain character

Report •

#1
April 8, 2013 at 01:36:26
What's wrong with the replace option under edit? Why is a batch file needed?

How do you know when a politician is lying? His mouth is moving.


Report •

#2
April 8, 2013 at 01:45:04
Thanks for the quick answer. The part I'm asking for is just a sub-routine of a more comprehensive task. That's why I need to have it automated.

Report •

#3
April 8, 2013 at 10:24:18
✔ Best Answer
:: =====  script starts here  ===============
:: 
:: deedee77.bat  2013-04-09  0:14:04.39
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
set S=!S:~0,1!
if "!S!" equ "%%" (
  echo.
  echo.%%a
  ) else (
  echo.%%a
)
)>> newfile
::======  script ends here  =================

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
April 9, 2013 at 00:41:04
Great! Thank you very much! Exactly what I needed;)

Report •

Ask Question