Check file content type

I have a shell script that takes a file and uses "syncsort" to sort contents.
I want to add a condition to check whether the input file is textual or binary format. If textual, the "syncsort" will be used to sort the files contents. Otherwise, the sorting process will be skipped.

Note that the input file extension will be always fixed and cannot be used to determine the file content type.

Below is partial content of the shell script file.

cd ${homedir}

# I want to add the if condition here

syncsort /INFILE ${infile} reclegnth 20 /OUTFILE ${infile}.out OVERWRITE

# if ends here

Use file command on your file and replace "ASCII text" by the output of file command in your system.

Can you please give the command of file to find out ASCII/binary.
Thank you

There is no such option to find out. You have to use the file command, and then do string comparison as explained by anbu23.

$ file t.pl
t.pl: ASCII text
$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), stripped