tech talks #1 - one-line solutions! :D

in #linux4 years ago

for starters: i'm also a "techie-techie guy", dealing with linux since mid 90s. =)

--->8 snip 8<---
don’t know about you, but i simply love one-line solutions! yesterday i wrote a relatively long text about a topic that haunts us every now and then – even though the motivation of those who think a military coup would solve our problems is somehow understandable, i should say that no dictatorship of any kind is a feasible way out. (but i digress…)

so… i’ve got used to write in small caps – this dates from the very beginning of the Internet in here (circa 96). besides, at that time the utf-8 and other encoding standards were not mature as they are today – remember the ascii ribbon campaign?

the problem: how to convert every first letter of the sentences to upper case? i knew the capabilities of the command tr, which – among many other functionalities – performs this translation. however, it would fail to tackle the issue, given i had a pattern: “. [:alpha:]”.

here comes the winner! sed! you just have to prefix the pattern you want to use with the corresponding option: \L for lower case, \U for upper. then:


i love this sh*t! haha! xD$ cat aa aaa. bbbbb. cccc. ddddd. eeeee. $ sed 's/^\(.\)/\U\1/; s/\. \(.\)/. \U\1/g' aa Aaa. Bbbbb. Cccc. Ddddd. Eeeee.

btw, drop a comment if you are aware of another way of doing it! ;)