Some different approaches:
1/ If you want to do this every time the app runs, then load a database because "{ ?s owl:sameAs ?o }" is then an indexed access to the data and is fast.
2/ If you are doing it once only, then grepping the N-Triples version of the file is sometimes (depressingly!) effective.
Andy