From owner-freebsd-questions Mon Sep 23 19:55:42 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DBCD837B47A for ; Mon, 23 Sep 2002 19:55:37 -0700 (PDT) Received: from mail.au.darkbluesea.com (mail.au.darkbluesea.com [203.185.208.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id 92AD743E6A for ; Mon, 23 Sep 2002 19:55:36 -0700 (PDT) (envelope-from d.anker@au.darkbluesea.com) Received: (qmail 2558 invoked by uid 82); 24 Sep 2002 02:54:24 -0000 Received: from unknown (HELO ?10.0.0.188?) (10.0.0.188) by mail.au.darkbluesea.com with SMTP; 24 Sep 2002 02:54:24 -0000 Subject: Re: find case-insensitive challenge [cut/sed] From: Duncan Anker To: Peter Leftwich Cc: FreeBSD LIST In-Reply-To: <20020923221952.A20965-100000@earl-grey.cloud9.net> References: <20020923221952.A20965-100000@earl-grey.cloud9.net> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 24 Sep 2002 12:53:56 +1000 Message-Id: <1032836037.24108.218.camel@duncan> Mime-Version: 1.0 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 2002-09-24 at 12:24, Peter Leftwich wrote: > On Mon, 23 Sep 2002, Giorgos Keramidas wrote: > > On 2002-09-22 21:53, Peter Leftwich wrote: > > > That leads me to wonder about using "rev" to reverse the order of > > > characters on the line and "cut" using a field delimiter of "." :) :) > > You probably could, and then use rev to fix the lines back to their > > normal form too. `rev | cut -d. -f2- | rev` > > I definitely favor "cut." How common across the various Unices/Unixes is > cut, that is, does Sun/Solaris or Linux come with cut included? It's been on every box I've tried to use it on - SunOS, Solaris, Digital UNIX, AIX, FreeBSD, Linux ... > > > You can do that with sed(1) too, though: `sed -e 's/\.[^.]*$//'` > > Can you say in poor-man's terms what the above line does? I used to use > `sed -e 's/this/that/g'` often but haven't for a few years now. The way I > would remember the command was "sed edit substitute this for that _g_ood > we're done" even though I am aware the g is for global. `sed -e 's/\.[^.]*$//'` That says match a literal period followed by zero or more non-period characters up to the end of the line, and delete them. Or to put it another way, chop the file extension off - if it was something like 'foo.tar.gz' it would become 'foo.tar' and not 'foo' > > > Both of these should strip the `.xxx' extension of all input lines. > > Then, there's Perl, awk, and a few other tools. Practically unlimited > > ways of doing the same thing :) > > Giorgos. > > I wonder if there is a book just chock full of sed, awk, cut, and perl > examples dissected into layman's terms... :) Maybe an ORA.COM book? ORA has several books :-) A book called 'sed and awk' which I've never really read too much of since I discovered Perl just after purchasing it. There are several Perl books - if you want examples, I would suggest trying "The Perl Cookbook." You might also want to pick up a copy of "Mastering Regular Expressions." As far as the use of cut goes, it doesn't really warrant a book of its own (it doesn't do much beyond what the man page says), but you may find it used in various scripts around the place Regards, Duncan Anker To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message