Bash String to Lower or Upper Case: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * bash =tr= <syntaxhighlight lang='bash'> echo "${text}" | tr '[:upper:]' '[:lower:]' </syntaxhighlight> =awk= <syntaxhighlight lang='...")
 
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:


=tr=
=tr=
<syntaxhighlight lang='bash'>
* [[Tr#To_Uppercase|tr to uppercase]]
echo "${text}" | tr '[:upper:]' '[:lower:]'
 
</syntaxhighlight>
=awk=
=awk=
<font color=darkgray>NOT TESTED</FONT>
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
echo "${text}" | awk '{print tolower($0)}'
echo "${text}" | awk '{print tolower($0)}'
</syntaxhighlight>
</syntaxhighlight>
=bash 4=
=bash 4=
<syntaxhighlight lang='bash'>
* [[Bash_Parameter_and_Variable_Expansion#To_Uppercase|bash 4 tp uppercase]]
${text,,}
* [[Bash_Parameter_and_Variable_Expansion#To_Lowercase|bash 4 tp lowercase]]
</syntaxhighlight>
 
=sed=
=sed=
<font color=darkgray>NOT TESTED</FONT>
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
echo "${text}" | sed -e 's/\(.*\)/\L\1/'
echo "${text}" | sed -e 's/\(.*\)/\L\1/'
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 01:35, 11 December 2019

Internal

tr

awk

NOT TESTED

echo "${text}" | awk '{print tolower($0)}'

bash 4

sed

NOT TESTED

echo "${text}" | sed -e 's/\(.*\)/\L\1/'