I have a little project to build bash script that search in the OS ( Linux/Solaris ) the current IP address from files and replace them with other IP address.The problem is that IP address could be in text file or in not text file as binary/data files, etc.I use the command:file mime $PATH ( --mime is valid only for Linux )In order to verify if file is text file, or not text file ( as binary or data file, etc )Please advice if I do the correct thing. Is my conclusion correct?For example if command: file mime $PATHReturn the results text/plain Then its text/ascii file, if not then it's not text file ?The second question: file mime--mime flag is valid only for Linux but not exists in Solaris, so what the alternative for Solaris?As all know file command sometimes not identify exactly the definition of the target file, so if someone have other idea how to identify text file, I will be happy to get any brilliant suggestion.
Identify text/ascii files in Linux/Solaris
linux;bash;shell script;filesystems;perl
find /location -type f -print | xargs fileshould be quite portable. You can then look for [Tt]ext, etc. You'll need to do a list of the various possible outputs (script, text, ...) and see which ones you want to look into.