I am trying to remove duplicate numbers within parentheses using sed.
So I have the following string:
Abdc 1234 1234 (5678) (5678) (9012) (9012) (3456)
I want to use sed to remove any 4-digit numbers within the parentheses, including the parentheses. So my string should look like this:
Abdc 1234 1234 (5678) (9012) (3456)
In this case the “(5678)” and “(9012)” were removed because they were 4-digit numbers within parentheses that repeated. The “1234” numbers were not removed because they were not within parenthesis. The “(3456)” was not removed because it was not repeating.
I do not know how to do this with
sedbut you could try the following withawk:Output:
This loops through the line fields then prints each field only if it has never been seen before or if it is not starting with
(.