c++ - Mapping a string to a unique number? -


is there nice bash 1 liner map strings inside file unique number?

for instance,

a b b c c 

should converted into

1 1 2 2 3 3 

i implementing in c++ bash one-liner great.

awk '{if (!($0 in ids)) ids[$0] = ++i; print ids[$0]}' 

this maintains associative array called ids. each time finds new string assigns monotically increasing id ++i.

example:

jkugelman$ echo $'a\nb\nc\na\nb\nc' | awk '{if (!($0 in ids)) ids[$0] = ++i; print ids[$0]}' 1 2 3 1 2 3 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -