From owner-freebsd-questions@freebsd.org Sun Sep 17 20:32:22 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2DBEBE0334C for ; Sun, 17 Sep 2017 20:32:22 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay12.qsc.de (mailrelay12.qsc.de [212.99.163.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A8DC46CFB5 for ; Sun, 17 Sep 2017 20:32:21 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay12.qsc.de; Sun, 17 Sep 2017 22:32:13 +0200 Received: from r56.edvax.de (port-92-195-1-252.dynamic.qsc.de [92.195.1.252]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 7E97C3CBF9; Sun, 17 Sep 2017 22:32:15 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v8HKWBhs002224; Sun, 17 Sep 2017 22:32:11 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Sun, 17 Sep 2017 22:32:11 +0200 From: Polytropon To: mfv@bway.net Cc: freebsd-questions@freebsd.org, Polytropon Subject: Re: case command Message-Id: <20170917223211.bd017503.freebsd@edvax.de> In-Reply-To: <20170917160758.18b6000e@gecko4> References: <59BE89E1.3050209@gmail.com> <20170917193722.7d2ecbe3.freebsd@edvax.de> <20170917160758.18b6000e@gecko4> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay12.qsc.de with DB9DE6A3788 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1342 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Sep 2017 20:32:22 -0000 On Sun, 17 Sep 2017 16:07:58 -0400, mfv wrote: > > On Sun, 2017-09-17 at 19:37 Polytropon 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. > >>=20 > >> Is there such a command line command? =20 > > > >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. ;-) > > > > > > >=20 > Hello, >=20 > Yes, Indeed. Here is an alternative using gsed: >=20 > gsed -e 's/(.*)/\L\1/' < input | ... >=20 > 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: >=20 > y/=C2=C3=C4=C5=C1/=E2=E3=E4=E5=E1/ For localized 1-byte codes (like german Umlauts), dd can be used. All methods mentioned so far seem to work correctly: % echo "M=C4RCHENB=DCGELR=D6STER" | dd conv=3Dlcase m=E4rchenb=FCgelr=F6ster 0+1 records in 0+1 records out 19 bytes transferred in 0.000030 secs (632474 bytes/sec) % echo "M=C4RCHENB=DCGELR=D6STER" | tr '[A-Z]' '[a-z]' m=E4rchenb=FCgelr=F6ster % echo "M=C4RCHENB=DCGELR=D6STER" | tr '[:upper:]' '[:lower:]' m=E4rchenb=FCgelr=F6ster % echo "M=C4RCHENB=DCGELR=D6STER" | awk '{ print tolower }' m=E4rchenb=FCgelr=F6ster 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. :-) --=20 Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...