This is an interesting question. I like @txnelson 's solution. In addition to his approach, this is a situation where regular expressions can be handy, so here is another way to do it.
The two examples provided have the following patterns:
- a prefix may be present, for example "abp-g5."
- the desired string/characters follow the prefix
- the repeated/duplicated characters exactly match the desired string/characters
- the repeated/duplicated characters are separated from the desired characters by an underscore
- there is nothing other than duplicated characters at the end of the string
- there is at least one repeated/duplicated string/characters present
Assuming these rules accurately define the column names that need changing, the following code will update all the column names in the "current data table" that match the above assumptions. The column names that do not match the assumptions will not be changed.
names default to here(1);
dt = current data table();
for( k = 1, k <= n cols(dt), k++,
colName = column(dt, k) << get name();
colName = regex( colName, "^.*?(.+)(?:_\1)+$", "\1" );
try( column(dt, k) << set name( colName ) );
);