search for any number, and retain them in replacement

Hello!

Here is what I am trying to do: I am taking a class at school that is using a lot of literature that is in the public domain, and available for free on the web. Rather than read them online in HTML, I have been pulling them down and quickly and dirtily tagging them up and typesetting them with LaTeX.

I am pulling down a piece of work that has a lot of end notes, and i would like to write a script so that I can add all of the \endnotemarker and \endnotetext tags relatively automatically.

All of the notes are already numbered appropriately, but not tagged.

What I would like to do, with either Perl or SED or AWK or VI or whatever would be best... is search for all integers and then apply the tag before an after it. The problem I am running into, is that my search term is something like

* [0-9]+ #to find in text numbers
^[0-9]+  #to fine end note numbers

but, obviously, if I use a replace term, it is not going to use the number that was found, but literally whatever I write in the replace term (this is all in VI right now, sorry I was not clear).

This is why I think I need some kind of a script that will find the number, store the number in a variable and then I can call upon that specific variable in the replacement term. The variable would update each time a new integer is found.

I might thinking about this all wrong, but can anyone think of a simple way to do this? It is not life and death, it would just make the file I generate something worth keeping around for re-reading.

Thanks!

EDIT: now that I think about it, I dont think this will really work for the LaTeX operation, but does anyone know how to write a script to do this in general... like if I wanted to add a word after every time a number appears in a paragraph, without changing the number?

echo 'foo 1234 bar fred 56 7890 baz' | sed 's/[0-9][0-9]*/&<myWordHere>/g'

I'll play with this, thank you! I guess the part of the command that you taught me was the

&

I did not know of that function! I'll look it up in the manual... thanks!

> echo "an apple every 13 days helps 169 people" | sed 's/\([0-9][0-9]*\)/(&)/g'
an apple every (13) days helps (169) people

echo "an apple every 13 days helps 169 people"
input data

| sed
pipe to string editor

's/
substitute

\(
escape before the ( character

[0-9][0-9]*
looking for 2 or more numbers

\)
escape before the closing ) character

/
change to what follows

(&)
here, I am saying I want my # in parenthesis
Note the & carries forward what I found in initial search

/g'
close replacement, tell global (as many as it finds)

actually, we don't even need a 'capture':

$ echo "an apple every 13 days helps 169 people" | sed 's/[0-9][0-9]*/(&)/g'
an apple every (13) days helps (169) people