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
Post a Comment