Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2007
    Posts
    6

    Unanswered: Can you test a file for ASCII encoding?

    Hi all.

    I'm still fairly new at this (shell scripting) so bear with me....

    I currently have a script that tests to see if a $1 is a file :

    Code:
    if [[ -f $filename ]] then
       do_stuff
    else
       echo "$filename is not a regular file"
    fi
    My question: is there a way to test that the file $filename is in ASCII and not another encoding type? I am using Korn shell.

    Thanks for any help.

    EDIT: I should note that $1 is assigned to filename before this code segment.
    Last edited by brianr8011; 07-16-08 at 14:44.

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    You can use the "file" utility if it is installed.

    $ file Configurator.hpp
    Configurator.hpp: ASCII C++ program text
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •