Re: [SLE] Using TR to produce Initial Caps in bash script
"Chris Goodnough" <chris@eclipsecat.com> writes:
Good day all,
I'm working on a bash script and need some help. Can someone please tell me what the syntax is for using the "tr" command to produce an initial capped word, or if it's possible to accomplish this without shaving the initial variable down to the first letter?
I've tried what looked obvious without any luck, though I can translate to all upper or all lower cases no problem. I'm using the following command to test:
echo sometext | tr CHAR1 '[A-Z]'
Expected results "Sometext", returned "sometext".
Am I missing an option or is SET1 just completely wrong? Thanks in advance.
You cannot do this using just tr -- you need to 'escalate' to sed, awk or perl. In perl: markgray@soyo:~> echo sometext and some more text| perl -pe 's/\b(\w)/\u$1/g' Sometext And Some More Text
Thanks Mark. I had intended on rewriting the script in Perl anyways but was thinking that I could "tr" in a simple script, and being that I'm just starting out with perl, this will help.
Good day all,
I'm working on a bash script and need some help. Can someone please tell me what the syntax is for using the "tr" command to produce an initial capped word, or if it's possible to accomplish this without shaving the initial variable down to the first letter?
I've tried what looked obvious without any luck, though I can translate to all upper or all lower cases no problem. I'm using the following command to test:
echo sometext | tr CHAR1 '[A-Z]'
Expected results "Sometext", returned "sometext".
Am I missing an option or is SET1 just completely wrong? Thanks in advance.
You cannot do this using just tr -- you need to 'escalate' to sed, awk or perl. In perl: markgray@soyo:~> echo sometext and some more text| perl -pe 's/\b(\w)/\u$1/g' Sometext And Some More Text -- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
participants (2)
-
Chris Goodnough
-
Mark Gray