0

Is there a way to use a batch file to open .txt files and remove anything that is not numbers or letters (also leaving the tabs and spaces).

I am new to writing batch files but I think this is the best option for what I need to do.

Background
I have .qrd files (can be open as .txt files) and I use VBA to open them and add the information required to excel for reporting reasons. My issue is that some of the files have little blocks in, I am assuming they are unrecognizable characters from the database, this plays havocs with my VBA/Reports.

Any thoughts welcome, I have been searching for a while now and have figured out how to delete characters from a batch file but not how to delete anything that doesn't match a criteria.

1
  • 1
    Welcome on Stack Overflow which is place where programmers can put a question to find help on a specific coding problem they have on their code, see help topic What topics can I ask about here? So please show us your efforts on coding this task by yourself and where you stuck. Why not using VBA to cleanup the files? Why not using a text editor with Perl regular expression Replace in Files support like UltraEdit for this task? But to answer your question, it would be possible to do this with command processor, but using something other would be better. Commented Dec 17, 2015 at 15:39

1 Answer 1

1

Well, batch isn't the best language to do this in,stability and speed wise. However it can be done.

@echo off
setlocal enableDelayedExpansion
:[ replace '█' with whatever you may have via copy/paste ]

:[ to replace all '█' with spaces; ]
set "variable=!variable:█= !"

:[ to delete all '█' without leaving spaces; ]
set "variable=!variable:█=!"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.