Skip site navigation (1)Skip section navigation (2)
Date:      24 Sep 2002 12:53:56 +1000
From:      Duncan Anker <d.anker@au.darkbluesea.com>
To:        Peter Leftwich <Hostmaster@Video2Video.Com>
Cc:        FreeBSD LIST <FreeBSD-Questions@FreeBSD.Org>
Subject:   Re: find case-insensitive challenge [cut/sed]
Message-ID:  <1032836037.24108.218.camel@duncan>
In-Reply-To: <20020923221952.A20965-100000@earl-grey.cloud9.net>
References:  <20020923221952.A20965-100000@earl-grey.cloud9.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <Hostmaster@Video2Video.Com> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1032836037.24108.218.camel>