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. Martin


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. Martin