case command

Polytropon freebsd at edvax.de
Sun Sep 17 20:32:22 UTC 2017


On Sun, 17 Sep 2017 16:07:58 -0400, mfv wrote:
> > On Sun, 2017-09-17 at 19:37 Polytropon <freebsd at edvax.de> 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. ;-)
> >
> >
> >
> 
> Hello,
> 
> 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'.

This only works with GNU sed (gsed), to be installed from ports.
FreeBSD's native sed implementation does not support \L and \U,
so you'd have to install GNU sed additionally.



> 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.

If awk is already part of the pipe chain, it's not a problem
to use it for this task.



> 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:
> 
>  y/ÂÃÄÅÁ/âãäåá/

For localized 1-byte codes (like german Umlauts), dd can be used.
All methods mentioned so far seem to work correctly:

	% echo "MÄRCHENBÜGELRÖSTER" | dd conv=lcase
	märchenbügelröster
	0+1 records in
	0+1 records out
	19 bytes transferred in 0.000030 secs (632474 bytes/sec)

	% echo "MÄRCHENBÜGELRÖSTER" | tr '[A-Z]' '[a-z]'
	märchenbügelröster

	% echo "MÄRCHENBÜGELRÖSTER" | tr '[:upper:]' '[:lower:]'
	märchenbügelröster

	% echo "MÄRCHENBÜGELRÖSTER" | awk '{ print tolower }'
	märchenbügelröster

This is on a ISO-8859-1 localized system. Even though it is technically
possible, I don't think those "edge cases" will appear in a domain
name list. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...


More information about the freebsd-questions mailing list