I have the following file:
blue yellow red black yellow
blue red black yellow red black
yellow red red purple yellow
How do I append a unique ID to each occurrence of the word red
so that the output is similar to this:
blue yellow red1376049638182 black yellow
blue red13760496381928 black yellow red1376049631827 black
yellow red1376049631988 red13760496371827 purple yellow
I tried the following command:
sed "s/red/red$(node -e 'console.log(new Date().getTime())'; sleep 0.001s)/g" file
but very soon realized that the ID (in this case a time) is only generated once and replaced globally in the entire file. Thus, the solution must somehow use a loop though I'm not sure how to filter out the occurrences of red and make sure each has a unique ID appended to it.