Artificial intelligent assistant

AWK/GAWK adding character after pattern is matched I have the following data structure in my test file: "111","222","AAABBB","333","444","555" I want to transform the third field so there is a '-' after the 3rd [A-Z] like so: "111","222","AAA-BBB","333","444","555" Is using the split() function the best tool for this job? Here is what I've attempted: awk 'BEGIN{OFS=FS=","} {split($3, a, "[A-Z]{3}", seps); print seps[1]"/"seps[2]};' test The above command does what I want, but how can I print the whole row including my updated $3 field? Result: AAA-BBB

Short **`awk`** solution:


awk 'BEGIN{ OFS=FS="," }{ sub(/[A-Z]{3}/, "&-", $3) }1' file


* `[A-Z]{3}` \- regex pattern to match 3 uppercase letters
* `&` \- stands for the precise substring that was matched by the regexp pattern



* * *

The output:


"111","222","AAA-BBB","333","444","555"

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 00bf9a4c0e199284ced9e3156febccb4