case command

mfv mfv at
Sun Sep 17 20:08:07 UTC 2017

> On Sun, 2017-09-17 at 19:37 Polytropon <freebsd at> wrote:
>On Sun, 17 Sep 2017 10:42:41 -0400, Ernie Luzar wrote:
>> Looking for a system command that a I can pip a file through to
>> change all uppercase content to lower case.
>> Is there such a command line command?  
>Several ones. One is to use tr:
>	... | tr '[A-Z]' '[a-z]' | ...
>Or with character classes:
>	... | tr '[:upper:]' '[:lower:] | ...
>You can also use awk for this task:
>	... | awk '{ print tolower($0) }' | ...
>You can use this within the awk portion of your script, too.
>Or shortened:
>	... | awk '{ print tolower }' | ...
>But keep in mind: Things like german Umlauts usually won't
>be processed correctly.
>Those are a few possible solutions. There are more. ;-)


Yes, Indeed. Here is an alternative using gsed:

 gsed -e 's/(.*)/\L\1/' < input | ...

To convert from lower case to upper case, change '\L' to '\U'.

As gsed operates on one line at a time it will not be as fast as other
solutions but has the merit of working on very large files when memory
is an issue.

It is also able to convert some Unicode, at least some of the Latin-1
Supplements and Latin Extended-A.  If conversions are needed for a
particular language not already covered by gsed then the y-command
could be added. For example:


This is an artificial example.  Since gsed already handles this
conversion the y-command would not be needed.  I'm not well versed in
Unicode except for a few Latin code pages and gsed works as expected
for those pages.

Cheers ...


More information about the freebsd-questions mailing list