Finding delimiter

Hi,
I need to find the field separator for the given files.

Ex-
abc.txt is "|" delimited file , when I give command the output should be "|" and that shud store it in another variable.

This is same with csv files or any other delmited file. If I give the filename it shud give the delimited present in the file.

Thanks in advance..!

There is no way to know for certain, what the delimiter is, because it is a matter of interpretation and not a "property" of the file.

For example:

abc,def|ghi,jkl

You can't tell for sure, if the comma or the pipeline is the delimiter in this line.

Explain an algorithm, how you would find out the delimiter, and we might be able to advise.