Translate

Archives

Script to Check for Control Characters in File

Here is how to check for and display lines from a text file that contain control characters except for line endings (which are also control characters!). $ grep “[^[:print:]]” infile | cat -nvt Here is a simple script that will output a message if a text file contains any control characters other than line endings. #!/bin/bash if grep “[^[:print:]]” infile > /dev/null 2>&1 then printf “Control characters present in filen” else printf “No control characters in filen” fi This should work in all locales.