Hi all,
I need to replace all occurrences of a specific string with a blank space. More precisely, I need a batch file to find all "NaN" in a text file, and replace it with " " (a blank space). How can I do this?
Bests
CB
Batch to find and replace
Moderator: DosItHelp
Re: Batch to find and replace
Try
Native Batch could replace it in a file using a FOR loop. You have to process line by line, replace all found NaN's by spaces and write it to a new file. You will find some examples if you use the search function of this forum.
But using native batch has some disadvantages:
- it's verry slow
- processing of empty lines is tricky
- you have to escape all found special characters (^<>|&) before you can write the new line
- replacing by batch is not case sesitive (so nAn or nan are replaced too)
I suggest to use a small tool in VBS that I posted here. Save the code as "Xchange.vbs"
Now you can call this tool in a batch file:
xchange.vbs "your.txt" -l "NaN" -l " "
Regards
aGerman
Code: Select all
set string=MyNaNString
set "string=%string:NaN= %"
echo %string%
Native Batch could replace it in a file using a FOR loop. You have to process line by line, replace all found NaN's by spaces and write it to a new file. You will find some examples if you use the search function of this forum.
But using native batch has some disadvantages:
- it's verry slow
- processing of empty lines is tricky
- you have to escape all found special characters (^<>|&) before you can write the new line
- replacing by batch is not case sesitive (so nAn or nan are replaced too)
I suggest to use a small tool in VBS that I posted here. Save the code as "Xchange.vbs"
Now you can call this tool in a batch file:
xchange.vbs "your.txt" -l "NaN" -l " "
Regards
aGerman
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: Batch to find and replace
Thanks you two for your replies. The vbs did a great work!
Bests regards
Bests regards
Re: Batch to find and replace
Thanks you two for your replies. The vbs did a great work!
Bests regards
Bests regards