PayPal is the easiest way to receive money online. Get one now or Click here to sign up. Sign up for PayPal and start accepting credit card payments instantly.

Convert easily a Unicode file to ASCII

The TYPE command
TYPE is used mostly to view small ASCII files, like AUTOEXEC.BAT.

But it can als be used to:

View text files that may be in use
Remove a line from a text file
Show size of files in use
Convert Unicode to ASCII

View text files that may be in use
TYPE has at least one feature that makes it well suited to perform other tasks than plain text file viewing: it doesn't lock the file it views.
This makes it an excellent program to view and even copy log files that are locked by another program.
The viewing will be obvious, here, but how about copying? Take a look at the example:

TYPE logfile.log > logfile.bakWithout the redirection to logfile.bak this would show the contents of logfile.log on screen.
Because of the redirection, though, these contents will now be stored in logfile.bak.
That way, the content of logfile.bak will be identical to logfile.log's, though it will have a different timestamp.

This may be useful if you need to copy a text file that may be in use, when COPY may fail.

Remove a line from a text file
This example demonstrates the combined use of TYPE and FIND to remove a line from an ASCII file (warning: real DOS only):

TYPE C:\CONFIG.SYS FIND /V /I "SHARE.EXE" > C:\CONFIG.SYSSince we use piping of TYPE's standard output to FIND's standard input, the content of CONFIG.SYS is stored in one or more temporary files before FIND's standard output will overwrite CONFIG.SYS again.
Without piping to FIND's standard input, CONFIG.SYS would be opened by TYPE and at the same time be overwritten by TYPE's standard output.
This would result in either an error message (if you're lucky) or an empty CONFIG.SYS.

Warning: This trick won't allways work in multi-tasking environments like Windows NT or OS/2! You may find that you end up with an empty file using this trick.
Use different source and target file names to be on the safe side.

Show size of files in use
I often use TYPE to check a download's progress:
If you use DIR to display file sizes, files being downloaded seem to have a file size of 0 bytes.
By using TYPE once to display the contents of the file, next time DIR will show the actual amount of bytes already downloaded.
This won't hurt the download, since TYPE does in no way lock the file.
Use TYPE and DIR again to check on download progress:

DIR download_in_progress
TYPE download_in_progress > NUL
DIR download_in_progress
download_in_progress is the name of the file being downloaded.

Convert Unicode to ASCII
In Windows 2000 and XP, TYPE offers a simple method to convert Unicode files to ASCII:

TYPE MyUnicode.txt > MyASCII.txtOr, if "extended" ASCII characters like ë or à may be involved:

CHCP 1252
TYPE MyUnicode.txt > MyASCII.txt
1252 is the most commonly used codepage for western languages in Windows 2000 and later.
Use a different code page for other languages.
In Windows 9x use 437 (US) or 850 (Europe).

Note: To save and restore the original codepage, use this command before changing the codepage:


and then use the following command to restore the original codepage afterwards:


Conversion from ASCII to Unicode is not as simple.

You can open an ASCII file in Notepad and then choose Unicode instead of ANSI in the "Encoding" field of the "Save As" dialogue.

To allow ASCII to Unicode conversion from the command line I wrote ASCII2UC.vbs.
Its usage is simple:

CSCRIPT.EXE //NoLogo ASCII2UC.VBS ascii_file unicode_file

Original Post Here

No comments:

WebProNews Feed

eWeek - RSS Feeds

HowtoForge - Howtos and Tutorials

The Register

PayPal is the easiest way to receive money online. Get one now or Click here to sign up. Sign up for PayPal and start accepting credit card payments instantly.