To prefix unique words with "UNIQUE:" inside the file, I tried using the relx perl command, for example:
perl -e 'undef $/;while($_=<>){s/^(((?!\b\3\b).)*)\b(\w+)\b(((?!\b\3\b).)*)$/\1UNIQUE:\3\4/gs;print $_;}' demo
In a demo file containing:
watermelon banana
apple pear pineapple orange mango
strawberry cherry
kiwi pineapple lemon cranberry watermelon
orange plum cherry
kiwi banana plum
mango cranberry apple
lemon
Output:
watermelon banana
apple pear pineapple orange mango
strawberry cherry
kiwi pineapple lemon cranberry watermelon
orange plum cherry
kiwi banana plum
mango cranberry apple
UNIQUE:lemon
Unfortunately, backward link \ 3 does not seem to be processed if used in advance.
Is there any other way to achieve this with another regular expression or with other regular commands available in the Linux field ? (grep, sed, awk, ...)
Many thanks
EDIT:
Unfortunately, many of the solutions only work for a case that was incomplete, my apologies for this, it should also work on the text, for example:
{watermelon || banana}
apple = ( pear pineapple orange mango )
strawberry cherry
kiwi = pineapple = lemon = cranberry = watermelon
orange - plum = cherry
kiwi = banana + plum
mango = cranberry && apple
lemon
If this simplifies the problem, words may be prefixed with something like $ or @.