How to number unique words on each individual line, not miss paragraph?
<p>Before anything I am reading English language and programming, but I am beginner now. So I did a lot of methods to learn EN ( self-study ) but finally I make a personal method to learn.<br>
So I collected a lot of <strong>short story</strong> then, read those, day after day. Now I am doing this method as usual.<br>
A week a go I started to learn <strong>perl one-liner</strong> and it was so useful to me.</p>

<p>However, I get into <code>perl -pe '$q=0; s/(\w+)/++Sq." ".$1'</code><br>
for content:  </p>

<blockquote>
  <p>just another<br>
  perl hacker<br>
  hacking perl code</p>
</blockquote>

<p>it become to:  </p>

<blockquote>
  <p>1.just 2.another<br>
  1.perl 2.hacker<br>
  1.hacking 2.perl 3.code</p>
</blockquote>

<p>Okay, after I saw this <strong>perl one-liner</strong> I got an idea  </p>

<p>For example I read this short-story:  </p>

<blockquote>
  <ol>
  <li><p>Morning<br>
  He wakes up. He sees the sun rise. He brushes his teeth. His teeth are white. He puts on his clothes. His shirt is blue. His
  shoes are yellow. His pants are brown. He goes downstairs. He gets a
  bowl. He pours milk and cereal. He eats. He gets the newspaper. He
  reads.</p></li>
  <li><p>First<br>
  Day of School He goes to class. There is an empty seat in front. He sits in the seat. He looks around. There are different
  people. He says "hi" to the girl next to him. She smiles. The teacher
  comes in. She closes the door. Everyone is silent. The first day of
  school begins.</p></li>
  <li><p>Water on the Floor<br>
  She is thirsty. She gets a glass of water. She begins to walk. She drops the glass. There is water on the floor. The
  puddle is big. She gets a mop. She wipes the water off. The floor is
  clean. She gets another glass of water. She drinks it. She is happy.</p></li>
  <li><p>Babysitting<br>
  Casey wants a new car. She needs money. She decides to babysit. She takes care of the child. She feeds him lunch. She reads
  him a story. The story is funny. The child laughs. Casey likes him.
  The child's mom comes home. The child kisses Casey. Casey leaves. She
  will babysit him again.</p></li>
  </ol>
  
  <p>5.a docter<br>
  Sam is a doctor. He takes care of people. He smiles at them. He gives them medicine. He gives stickers to the younger
  patients. The younger patients like him. They see him when they are
  sick. He makes them feel better. This makes him happy. He loves his
  job. He goes home proud.</p>
</blockquote>

<p>As you can see, it is very easy. But at the beginning, it is not easy for someone who just started to learn English.  </p>

<p>So my idea is this. I want a script may be in <strong>bash</strong> or <strong>perl</strong> that I think <strong>perl</strong> is better, that script can read a lot of <strong>short-story</strong> that I have and for each unique work, it number the word in the place.  </p>

<p>For example in the above context that I put, I want something like this:  </p>

<blockquote>
  <p>1.He 2.wakes 3.up. He 4.sees 5.the 6.sun 7.rise. He 8.brushes 9.his 10.teeth 11.are 12.white He 13.puts 14.on his 15.clothes. ... so on.</p>
</blockquote>

<p>Here the first <strong>He</strong> is unique so number it to 1.<br>
And until the end of content the "He" word is ignored, and so on.
Then the script does this to second words, if it is unique, then numbers it, otherwise ignore it.  </p>

<p>Also the paragraph and each line <strong>must not miss</strong>, because I print it out in paper and read daily.  </p>

<p>For completing this idea to use by everyone else I need to have a <strong>database</strong> from one word that script is parsed so that I can after, for example 100 short-story, I see whet word I have read.<br>
And use this <strong>database</strong> for ignoring the repeated word in the new short-story that I want to read.  </p>

<p>Why am I doing this? Because this help me to know what word I have read and what word I have not read. Also It can be a good method for the others, so that they can learn English easily. please help me to develop this idea If you see something bad in my idea or if you know the similar idea like this, that have done,please tell me.</p>

<p><strong>In summary, I want a content that each word only once (one time) has been numbered</strong></p>

<p>Sorry guys, but I want to print the content without missing the paragraph. Please the photo </p>

<p><a href="http://i.stack.imgur.com/BfemJ.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/BfemJ.jpg" alt="my homework"></a></p>

<p>As you can see, I have to cross the new word in the <strong>new short story</strong> for read those in the future. The script must print paragraph with numbering word as usual so that I can save it, then I print it for reading on the paper.</p>

<p>I want to do in this form:
<code>$ script my_context.txt &gt; new_context.txt</code>  </p>

<p>Then I can print it out.</p>

<p>I am so sorry if you see some mistake in my writing. If you does not understand my idea please comment, so that I put explain it in more detail.  </p>

<p>Thank a lot!</p>

<pre><code>$ cat script.txt 
BEGIN {RS=" "; ORS=" "}       # the record is a word
{
    key=$0                    # separate key to clean it up
    gsub(/[^a-zA-Z]/,"",key)  # remove ".," etc.
    key=tolower(key)          # and capitals
    if(!(key in a)) {         # if not seen before
        print ++i; a[key]     # print the running number
    }
} 1                           # and the word
</code></pre>

<p>Run it:</p>

<pre><code>$ awk -f script.awk short_story_in_2_paragraphs.txt
</code></pre>

<blockquote>
  <p>1 He 2 wakes 3 up. He 4 sees 5 the 6 sun 7 rise. He 8 brushes 9 his 10 teeth 11 are 12 white He 13 puts 14 on his 15 clothes. His 16 shirt 17 is 18 blue. His 19 shoes are 20 yellow. His 21 pants are 22 brown. He 23 goes 24 downstairs. He 25 gets 26 a 27 bowl. He 28 pours 29 some 30 milk 31 and 32 cereal. He 33 eats. He gets the 34 newspaper. He 35 reads.</p>
  
  <p>He wakes up. He sees the sun rise. He brushes his teeth are white He puts on his clothes. His shirt is blue. His shoes are yellow. His pants are brown. He goes downstairs. He gets a bowl. He pours some milk and cereal. He eats. He gets the newspaper. He 36 reads.</p>
</blockquote>

<p>I don't understand the last number <code>36 reads</code>, thou :D.</p>

<p>Version 2(.1 :)</p>

<pre><code>BEGIN {RS=" "; ORS=" "}              # the record is a word
NR==FNR {a[$0]; next}                # read the database of words into memory
{
    key=$0                           # separate key to clean it up
    gsub(/[^a-zA-Z]/,"",key)         # remove ".," etc.
    key=tolower(key)                 # and capitals
    if(!(key in a)) {                # if not seen before
        print ++i; a[key]            # print the running number
        print key &gt;&gt; "database.txt"  # append word to database
    }
} 1                                  # and the word
</code></pre>

<p>Run it:</p>

<pre><code>$ awk -f script2.awk database.txt story.txt
</code></pre>

<p>It expect that <code>database.txt</code> exists and has at least one word in it:</p>

<pre><code>$ echo -n a\  &gt; database.txt
</code></pre>

python bash perl