Unix Shell - Lower casing all words in a file

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > Lower casing all words in a file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Lower casing all words in a file
laredotornado@zipmail.com

2007-12-04, 7:25 pm

Hi,

How do I lower case all the words in a text file? I'm running Fedora
Core 5 Linux and I don't have a preference on shells, although my
default is zsh.

Thanks so much, - Dave
Ed Morton

2007-12-04, 7:25 pm



On 12/4/2007 4:49 PM, laredotornado@zipmail.com wrote:
> Hi,
>
> How do I lower case all the words in a text file? I'm running Fedora
> Core 5 Linux and I don't have a preference on shells, although my
> default is zsh.
>
> Thanks so much, - Dave


tr '[A-Z]' '[a-z]' < file > tmp && mv tmp file

Ed.

Janis Papanagnou

2007-12-04, 7:25 pm

laredotornado@zipmail.com wrote:
> Hi,
>
> How do I lower case all the words in a text file? I'm running Fedora
> Core 5 Linux and I don't have a preference on shells, although my
> default is zsh.


dd if=text.in of=text.out conv=lcase


Janis

>
> Thanks so much, - Dave

John W. Krahn

2007-12-05, 1:42 am

Ed Morton wrote:
>
> On 12/4/2007 4:49 PM, laredotornado@zipmail.com wrote:
>
> tr '[A-Z]' '[a-z]' < file > tmp && mv tmp file


Why are you translating '[' to '[' and ']' to ']'?

tr 'A-Z' 'a-z' < file > tmp && mv tmp file



John
--
use Perl;
program
fulfillment
Chris F.A. Johnson

2007-12-05, 1:42 am

On 2007-12-05, John W. Krahn wrote:
> Ed Morton wrote:
>
> Why are you translating '[' to '[' and ']' to ']'?


Because there are versions of tr that require a range to be
enclosed in [].

> tr 'A-Z' 'a-z' < file > tmp && mv tmp file



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Wayne

2007-12-05, 1:42 am

Chris F.A. Johnson wrote:
> On 2007-12-05, John W. Krahn wrote:
>
> Because there are versions of tr that require a range to be
> enclosed in [].


Such as? Any such system is broken as it violates POSIX.

The only use of '[' and ']' with tr is in a character class,
such as:

$ tr '[:upper:]' '[:lower:]' <file

-Wayne
Chris F.A. Johnson

2007-12-05, 7:32 am

On 2007-12-05, Wayne wrote:
>
>
> Chris F.A. Johnson wrote:
>
> Such as?


AT&T SVR3.2

> Any such system is broken as it violates POSIX.


There was no POSIX then.

> The only use of '[' and ']' with tr is in a character class,
> such as:
>
> $ tr '[:upper:]' '[:lower:]' <file
>
> -Wayne



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Mikhail Teterin

2007-12-05, 1:24 pm

Wayne wrote:

> The only use of '[' and ']' with tr is in a character class,
> such as:
>
> $_tr_'[:upper:]'_'[:lower:]'_<file


This is the right method anyway, because the original poster did not
specify, that the file will only consists of US-ASCII characters, so [A-Z]
would fail to capitalize all of the [А-Я], etc.

The character classes, etc. may not be supported by some ancient systems,
but the original poster did specify, that they are using a (fairly) modern
Fedora 5.

-mi
Martien Verbruggen

2007-12-07, 7:31 am

On Wed, 5 Dec 2007 03:40:40 -0500,
Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
> On 2007-12-05, Wayne wrote:
>
> AT&T SVR3.2


SVR4 shipped in 1989 or 1990 or thereabouts. How many people are still
running SVR3.2? Not just for historical interest, but seriously?

Martien
--
|
Martien Verbruggen | Blessed are the Fundamentalists, for they
| shall inhibit the earth.
|
Ed Morton

2007-12-07, 7:31 am



On 12/7/2007 5:06 AM, Martien Verbruggen wrote:
> On Wed, 5 Dec 2007 03:40:40 -0500,
> Chris F.A. Johnson <cfajohnson@gmail.com> wrote:
>
>
>
> SVR4 shipped in 1989 or 1990 or thereabouts. How many people are still
> running SVR3.2? Not just for historical interest, but seriously?
>
> Martien


I don't know what version it is, but on the UNIX test harnesses we use in our
labs you still need '[' and ']'. Personally, I've been using that for the past
20 years or so, rarely use it, and have just never found a reason to change - in
fact this is the first time I've even considered checking to see if the "new"
syntax works on all the various UNIX systems I use.

Ed.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com