0

This is the first time ive posted here so I apologise if im in the wrong place.

I have a batch file that reads a list of domains from a text file and then does an nslookup ls against them, posting the results in their own text file.

Ive never had a problem with this until recently and I cant for the life of me work out why this has started happening.

All the files are perfect except for the first one! The first file name is always proceeded with "" (without the quotes) These files get read by another program I have written so it tends to cause a problem.

Heres the code that creates the files...

(
del /s /q "D:\Profile\Desktop\New_folder\Records\*.*"
for /f %%a in (D:\Profile\Desktop\New_folder\Domains\Domains.txt) do (
echo ls %%a >temp\tempfile.txt
echo exit >>temp\tempfile.txt
nslookup < temp\tempfile.txt > records\%%a.txt
)
)

Any help is much appreciated.

Cheers,

Aaron

Aaron
  • 1
  • 1
  • 2

1 Answers1

1

According to IBM Extendend Characterset the characters you mentioned have the hex codes EF BB BF which is the UTF-8 byte order mark ("BOM"), see Wikipedia. This means that the file Domain.txt seems to have been saved using UTF-8 character encoding with BOM recently.

In order to get rid of the characters, simply edit the file and save it without a BOM. See e.g. to How to make Notepad to save text in UTF-8 without BOM? how to do that or search for "remove BOM"

Note that UTF-8 without BOM is compatible to printable ASCII, i.e. "normal" characters encoded as UTF-8 will show correctly in most common charactersets such as IBM Extended Characterset.

If you cannot or do not want to edit the input file then you might get rid of the prefix in your batch script, see Substrings in http://www.robvanderwoude.com/ntset.php#StrSubst - eventually something like

set BOM_REMOVED=false
for ...
set X=%%a
if %BOM_REMOVED%==false set X=%X:~3%
set BOM_REMOVED=true
echo ls %X >temp\tempfile.txt
...
Community
  • 1
  • 1
halfbit
  • 3,414
  • 1
  • 20
  • 26
  • Hi halfbit, many thanks for your response. Im fairly confident that with your suggestions i will be able to resolve this. In the meantime, as this is part of a larger project I have been using different code to identify it and rename it. Thanks for your help. – Aaron Jan 19 '15 at 10:11