>> You can call sed from awk using system() but that's unlikely to be the
>> best solution. I'd do something like this:
>> awk 'BEGIN{lastNum = 1}
>> { key = val = $0; sub(/^[A-Z]*/,"",val); sub(val,"",key)
>> if (! (key in keys)) keys[key] = lastNum++
>> print keys[key] val
>> }' file
> Yes, thanks, I have used sub() which works perfectly (that I found in
> "The Awk Manual" on Google)
> I just don't understand why the while loop is even more than 100 times
> slower than awk (in both case, my algorithm was exactly the same)
Because a shell script is interpreted, and the loop has to be
explicitly coded (and interpreted on every loop); in awk, the loop
code is implicit, i.e., compiled into awk itself.
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
==================================================================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>