This might not be the appropriate forum to ask this question but I have an head-scratching problem with using sed in the Terminal app. The use of sed appears in a long command line pipe with several other sed invocations to change more static things in those data lines (intend putting them in a command file to clean up the line).
The data being processed is a CSV file of addresses like this
1 The Road, The Town, The County, The Post Code
1a The Road, The Town, The County, The Post Code
1b The Road, The Town, The County, The Post Code
2 The Road, The Town, The County, The Post Code
3 The Road, The Town, The County, The Post Code
4a The Road, The Town, The County, The Post Code
4b The Road, The Town, The County, The Post Code
4c The Road, The Town, The County, The Post Code
15z Street, Other Town, No County, Different Post Code
I want to replace the lower case a, b, c, … z after the digits with upper case A, B, C, … Z respectively.
With much discussion in other topics here about the use of ChatGPT I posted a request for a working sed command. It responded with:
sed ‘s/([0-9])([a-z])/\1\U\2/’
which resulted in U being inserted between the last digit and the lower case letter. Other responses included:
sed ‘s/([0-9])([a-z])/\1$(echo \2 | tr [:lower:] [:upper:])/’
which resulted in the echo being inserted.
When told that didn’t work and the \U didn’t work it responded with:
sed ‘s/([0-9])([a-z])/\1\U\2\E/’
which you can guess merely added U and E to the output. The question/response then cycled through the same output.
I have tried using sed’s -E option to enable extended REs but that does not improve the result.
So I have given up on an AI produced solution and now asking the sensible real intelligence for help.
BTW using Monterey 12.6 with bash version 3.2.57.1 (installed via homebrew) and whatever version of sed came with Monterey.