I have file test.txt which contains:
hwidjhcxgugdish0ikjhgy1khjkghvcgj3ihgyuhk1guijh2igkhbj2jkuigk1
And I have C header file test.h:
#define VAL1 0#define VAL2 1#define VAL3 2#define VAL4 3#define VAL5 0
I need to:
- for each number in test.txt (0-999) find which variable(s) in test.h have value equal to this number
- if this value has more than one variable - leave unchanged
- if only one - replace value with name of variable
In the end, the file test.txt should contain:
hwidjhcxgugdish0ikjhgyVAL2khjkghvcgjVAL4ihgyuhkVAL2guijhVAL3igkhbjVAL3jkuigkVAL2
Is it possible with sed/awk/bash/gcc/etc?