(Solved) How to capitalize all first characters of text?
(Solved) How to capitalize all first characters of text?
Hi.
In May 2015 I was in the need to have a function to capitalize first letter of file name.
Now I have the need to capitalize all first characters of all words in a text file or at least for per one line of text.
How to achieve?
Thanks
In May 2015 I was in the need to have a function to capitalize first letter of file name.
Now I have the need to capitalize all first characters of all words in a text file or at least for per one line of text.
How to achieve?
Thanks
Last edited by ITSMERSH on Mon 17 Dec 2018, 19:51, edited 2 times in total.
I think here you find :
https://stackoverflow.com/questions/153 ... -using-sed
The sed examples capitalize first char even if there's a - or a . between the words.
The awk example does not (may be more what you're looking for)
Fred
https://stackoverflow.com/questions/153 ... -using-sed
The sed examples capitalize first char even if there's a - or a . between the words.
The awk example does not (may be more what you're looking for)
Code: Select all
# echo "my word" | sed -e "s/\b\(.\)/\u\1/g"
My Word
# echo "my-word" | sed -e "s/\b\(.\)/\u\1/g"
My-Word
# echo "my word" | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1'
My Word
# echo "my-word" | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1'
My-word
Hello Rainer.
Here are a couple of ways of doing it in bash:
1) https://www.linuxquestions.org/question ... ing-268182
2)Source
A search on ask.com (or any serious search engine) will give you even
more solutions, e.g.:
https://www.ask.com/web?qsrc=1&o=0&l=di ... archTopBox
IHTH.
Here are a couple of ways of doing it in bash:
1) https://www.linuxquestions.org/question ... ing-268182
2)
Code: Select all
read -ra words <<< "<sentence>" && echo "${words[@]^}"
A search on ask.com (or any serious search engine) will give you even
more solutions, e.g.:
https://www.ask.com/web?qsrc=1&o=0&l=di ... archTopBox
IHTH.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Many ways to do this. Basically something similar to the sed example I proposed in 20015 should do it.
If file.txt contains
should produce
The sed expression turns the first character at line start (^.) or (|) any character (.) following a space or a tab ([ ]) into uppercase.
If for example you also need to change the capitalization of words that immediately follow a colon, you could add a colon to the characters in the [] brackets.
If file.txt contains
- these are my-words
in 2 lines of text
Code: Select all
sed -r "s/^.|[ ]./\U&/g" file.txt
- These Are My-words
In 2 Lines Of Text
The sed expression turns the first character at line start (^.) or (|) any character (.) following a space or a tab ([ ]) into uppercase.
If for example you also need to change the capitalization of words that immediately follow a colon, you could add a colon to the characters in the [] brackets.
wps office writer
wps office writer can do that!
- fabrice_035
- Posts: 765
- Joined: Mon 28 Apr 2014, 17:54
- Location: Bretagne / France
- puppy_apprentice
- Posts: 299
- Joined: Tue 07 Feb 2012, 20:32
You should wrote in more like haiku (Mochi is from Japan) style:musher0 wrote:MochiMoppei is way ahead of us, everybody should know that!
Code: Select all
MochiMoppei
everybody should know that!
is way ahead of us
http://www.haiku.art.pl/
Code: Select all
Aki mohaya
sono higurashi no
inochi ka na