Locating Hidden Characters in a File

As properly as the characters you can see in a net web site (or any other textual content file), there are a entire host of concealed characters that you won’t be able to see. Most of the time you you should not have to have to know exactly where these characters are, which is why they are concealed in the to start with place. At times while, possibly when you have to have to execute some particular processing on 1 or much more files, you have to have to locate and exhibit these characters. In this article I am going to clearly show how you can use a simple Perl script to locate and exhibit concealed characters in textual content files.

Right here is the script:

Find Hidden Characters

The script originally finds all the files in the ‘current’ listing (folder) that conclude with ‘.txt’. If you preferred to locate all the files that ended in ‘.htm’ or ‘.html’, for example, you would just have to have to change the ‘.txt’ in the line containing the grep command.

The next aspect of the script would make a backup of just about every file located, which is generally a great notion, and then lookups by way of just about every file identifying and exhibiting (within just about every file) the concealed characters located.

The characters that this script finds are the ‘end of line’ character, the ‘end of file’ character, the ‘tab’ character, and any command characters. You could of system edit the script to locate distinctive concealed characters if you preferred to.

The way the script finds and shows the characters is by making use of regular expressions. Frequent expressions supply a quite impressive way of looking for and (generally) changing strings in files. This script is prepared in Perl, which provides much more aid for regular expressions than any other language.

The regular expressions are contained in the lines commencing ‘$line =’. There are four of them in this script.

Functioning the Script

The script is designed to run on a local equipment. Therefore, in buy for it to do the job you will have to have to have a perl interpreter put in on your computer.

If you named the script ‘hidden.pl’, for example, you should be capable to run it by double-clicking it from in Windows Explorer. Alternatively, you could open up a command window, navigate to exactly where the script (and files to be processed) are positioned, and sort ‘perl concealed.pl’ at the command prompt.