Looking for a sed one-liner to do one of two things
by oldpink from LinuxQuestions.org on (#4SA60)
I'm trying to write up a sed one-liner (using pure sed and no pipes) to do two separate tasks:
1) Print out each line in a text file with its specific line number at the beginning of each line.
Change this:
Line one
Line two
Line three
Into this:
1 Line one
2 Line two
3 Line three
2) Find the last matching line number of text in a file.
Example:
Jones George
Doakes Joe
Jones George
PRINT "3" to indicate the last match.
Before I get asked why I don't just use awk or nl to do this, or why not pipe several commands using sed together to do it, my situation calls for pure sed as a one-liner only, plus I'm trying to learn more about the more advanced features of sed while I'm at it.
I'd be grateful for whatever anyone can tell me.


1) Print out each line in a text file with its specific line number at the beginning of each line.
Change this:
Line one
Line two
Line three
Into this:
1 Line one
2 Line two
3 Line three
2) Find the last matching line number of text in a file.
Example:
Jones George
Doakes Joe
Jones George
PRINT "3" to indicate the last match.
Before I get asked why I don't just use awk or nl to do this, or why not pipe several commands using sed together to do it, my situation calls for pure sed as a one-liner only, plus I'm trying to learn more about the more advanced features of sed while I'm at it.
I'd be grateful for whatever anyone can tell me.