From owner-freebsd-questions@FreeBSD.ORG Sat Jan 10 17:34:50 2004 Return-Path: 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 D9DE616A4D0 for ; Sat, 10 Jan 2004 17:34:50 -0800 (PST) Received: from sage.thought.org (dsl231-043-140.sea1.dsl.speakeasy.net [216.231.43.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED8BC43D1F for ; Sat, 10 Jan 2004 17:34:47 -0800 (PST) (envelope-from kline@thought.org) Received: from thought.org (root@tao [10.0.0.247]) by sage.thought.org (8.12.9/8.11.4) with ESMTP id i0B1aLGH015569; Sat, 10 Jan 2004 17:36:24 -0800 (PST) (envelope-from kline@thought.org) Received: (from kline@localhost) by thought.org (8.12.6/8.11.3) id i0B1YaS3044774; Sat, 10 Jan 2004 17:34:36 -0800 (PST) (envelope-from kline) From: Gary Kline To: Matthew Seaman , FreeBSD Mailing List , Gary Kline Message-ID: <20040111013434.GC44177@tao.thought.org> References: <20040110221036.GA44130@tao.thought.org> <20040110223308.GA4881@happy-idiot-talk.infracaninophile.co.uk> <20040110223907.GA16659@Uruk-Hai.Sanitarium.mine.nu> <20040110230218.GA5347@happy-idiot-talk.infracaninophile.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20040110230218.GA5347@happy-idiot-talk.infracaninophile.co.uk> X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: Observing 17 years of service to the Unix community User-Agent: Mutt/1.5.5.1i Subject: Re: perl script question. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Sun, 11 Jan 2004 01:34:51 -0000 X-Original-Date: Sat, 10 Jan 2004 17:34:34 -0800 X-List-Received-Date: Sun, 11 Jan 2004 01:34:51 -0000 On Sat, Jan 10, 2004 at 11:02:18PM +0000, Matthew Seaman wrote: > On Sat, Jan 10, 2004 at 11:39:07PM +0100, Björn Andersson wrote: > > On Sat, Jan 10, 2004 at 10:33:08PM +0000, Matthew Seaman wrote: > > > On Sat, Jan 10, 2004 at 02:10:36PM -0800, Gary Kline wrote: > > > > > Folks, > > > > > Let's see if perl can do this one; it's as obscure a task > > > > as I've run into. I have scores of files with: > > > > > A regular sentence, or phrase. then_one_containing_underscores_- > > > > between_each_word Followed by another regular, space-delimited > > > > sentence. Followed_by_another_string_with_underscaores. > > > > > Is there a perl way to get rid of the > > > > string_containing_underscores and leave the regular sntences?? > > > > perl -pi.bak -e 's/\s+\w+_\w+\.?//;' filename > > > If this occures more than once on a line we should have the line as this: > > perl -pi.bak -e 's/\s+\w+_\w+\.?//g;' filename > > Good point. Also, if the stuff_separated_by_underscores wraps around > onto more than one line, then there may not be any leading whitespace: > > perl -pi.bak -e 's/\s*\w+_\w+\.?//g;' filename > The lines do indeed wrap so this does the job on a test file. I do have the re-exp book but this one is far ovr my head. What do the "\s*" mean, and also thr "\.?/" ? Man, I'd never have gotten this one; at least not in *one* lines:-) Wow. thanks to everyone, gary -- Gary Kline kline@thought.org www.thought.org Public service Unix