Batch file edit text file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
msswamy
Posts: 2
Joined: 01 Feb 2021 21:06

Re: Batch file edit text file

#16 Post by msswamy » 02 Feb 2021 10:33

Thanks for your solution and it solved problem with exclamation mark ('!').
Regarding my new line issue, below is my sample text file.

Code: Select all

[Components.Section]
 Element_1
 !Element_2
 Element_3
Below are the string variables,

Code: Select all

set "replace=[Components.Section]"
set "replaced=[Components.Section]\nMyElement_0"
Finally my text file should come like below,

Code: Select all

[Components.Section]
 MyElement_0
 Element_1
 !Element_2
 Element_3
But it is coming like below,

Code: Select all

[Components.Section]\nMyElement_0
 Element_1
 !Element_2
 Element_3

T3RRY
Posts: 132
Joined: 06 May 2020 10:14

Re: Batch file edit text file

#17 Post by T3RRY » 02 Feb 2021 12:44

msswamy wrote:
02 Feb 2021 10:33
Thanks for your solution and it solved problem with exclamation mark ('!').
Regarding my new line issue, below is my sample text file.
\n is the literal string \n in batch scripting.

a linefeed can be defined as a variable using the following, however it requires delayed expansion to be enabled to use.

Code: Select all

@Echo Off
(Set LF=^


%= Linefeed. do not modify this or above three lines. =%)
Setlocal enabledelayedexpansion
>>"%~dp0outfile.txt" Echo/this is!LF!a demo
Type "%~dp0outfile.txt"

penpen
Expert
Posts: 1907
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch file edit text file

#18 Post by penpen » 07 Feb 2021 14:40

@msswamy: You didn't react to the post of T3RRY, so i don't know whether you found it solved your issue or not.

penpen

Post Reply