Checking order of lines in a file (Linux)

As you’ve identified, the error you’re seeing (Singular expression refers to non-unique object) suggests that there is more than one line that meets the defined criteria). For reference to common relevance error messages, their meaning, and suggested approaches, please see Common Relevance Error Messages.

For the scenario you describe above, can you be sure that the first instance of each line is the one you want to compare against? Are there other criteria we can use to positively identify the desired file lines?

For an example of ‘first instance’ comparison, perhaps something like the following:

(minimum of line numbers of lines whose (it as string contains "A") of it < minimum of line numbers of lines whose (it as string contains "C") of it) of file "foo.txt"