Article 57HPT sed to UPPERCASE specified characters

sed to UPPERCASE specified characters

by
danielbmartin
from LinuxQuestions.org on (#57HPT)
Have: a file in which every line contains a single word.
Have: n, a positive integer.

Want: an OutFile identical to the InFile except
the n-th character in every word is made UPPER CASE.

With this InFile ...
Code:hudson
mercury
nash
oldsmobile
packard
plymouth
pontiac
studebaker... this sed ...
Code:n=3
sed -r "s/(.{$(($n-1))})(.)(.*$)/\1\u\2\3/" $InFile >$OutFile... produced this OutFile ...
Code:huDson
meRcury
naSh
olDsmobile
paCkard
plYmouth
poNtiac
stUdebakerAs shown, this is a solved problem.

The next step is to effect the same transformation on a file with multi-word lines.

With this InFile ...
Code:hudson hornet
mercury marquis
nash rambler
oldsmobile omega
packard patrician
plymouth valiant
pontiac bonneville
studebaker lark... the desired OutFile is ...
Code:huDson hoRnet
meRcury maRquis
naSh raMbler
olDsmobile omEga
paCkard paTrician
plYmouth vaLiant
poNtiac boNneville
stUdebaker laRkCan this be done with a single sed? Please advise.

Daniel B. Martinlatest?d=yIl2AUoC8zA latest?i=oOakkV1KjzU:XztrdsuVjwM:F7zBnMy latest?i=oOakkV1KjzU:XztrdsuVjwM:V_sGLiP latest?d=qj6IDK7rITs latest?i=oOakkV1KjzU:XztrdsuVjwM:gIN9vFwoOakkV1KjzU
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments