How to convert specific text from a list into uppercase?
You are overdoing it, take advantage of your file structure to keep it simple!
If we find the string [United
in a line, uppercasing everything from the closing brace to the end of the line gives the result you are after. Translating this into Sed language,
sed '/\[United/s/].*/\U&/' file
Note that the above is specific to GNU Sed. If not available but in a POSIX system, you can use Ex (or see αғsнιη's Awk version) with a similar syntax:
printf '%s\n' 'g/\[United/s/].*/\U&/' '%p' | ex file
To save the changes to the file instead of printing the results, change %p
to x
.
Using awk
:
awk -F"[][]" '$2 ~/^United/ { $2="["$2"]"; $3=toupper($3); }1' OFS='' infile
within [...]
we defined both ]
and [
as field separator then checking against the second field if that start with United
text, if yes then add back []
around second filed (I assume there is no other column inclining these characters, else those fields will miss this); then we convert third column to its uppercase value; the idiom 1
is trigger awk
default print (a kind of always true condition).