You could use the
Function mode in Calibre Editor or my simple
Incremental IDs Sigil plugin.
(With my plugin you'd first have to add incremental ids and then use a regex to change the ids to tag values.)
BTW, if using epub3 books is an option for you, you could also use CSS with pseudo selectors to add line numbers. For details see
this thread.