[OT] - subthread - perl vs sed Re: [olug] Text search and Replace

Miller, Scott L (Omaha Networks) scott.l.miller at hp.com
Tue Nov 25 19:22:42 UTC 2003


Hmm, nope, I'd just be googling for you for the one sheeter.

But, having actually put together a couple of relatively hairy, yet still less than 10 lines long sed scripts, it is powerful, and great when you get it to work, but it's very terse, and I have yet to write one that worked intuitively.  For me, there were always problems when trying to deal with the edge cases correctly.  Course YMMV; This seems like an easy-ish one, as long as the string is guaranteed not to wrap lines on you...

I grabbed an O'Reilly pocket reference on Sed & Awk for $10 about a year ago.  I reference that continuously when trying to write sed...

-Scott

-----Original Message-----
From: Tim - DZ [mailto:iceburn at dangerzone.com]
Sent: None
To: 'Omaha Linux User Group'
Subject: RE: [OT] - subthread - perl vs sed Re: [olug] Text search and
Replace


Date: Tue, 25 Nov 2003 12:05:57 -0600
Message-ID: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAAlcyP5IjG/EaVDCvZhwZpAMKAAAAQAAAAuFqg/fplE0+UljZZ0rvr5QEAAAAA at dangerzone.com>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook, Build 11.0.5510
Thread-Index: AcOzeIGz+jqmROXkR+2X7u2EgVg7MwABVcuA
In-Reply-To: <00af01c3b378$79d95700$4501a8c0 at omaha.org>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-BeenThere: olug at olug.org
X-Mailman-Version: 2.1.1
Precedence: list
Reply-To: Omaha Linux User Group <olug at olug.org>
List-Id: Omaha Linux User Group <olug.olug.org>
List-Unsubscribe: <http://lists.olug.org/mailman/listinfo/olug>,
	<mailto:olug-request at olug.org?subject=unsubscribe>
List-Archive: <http://lists.olug.org/pipermail/olug>
List-Post: <mailto:olug at olug.org>
List-Help: <mailto:olug-request at olug.org?subject=help>
List-Subscribe: <http://lists.olug.org/mailman/listinfo/olug>,
	<mailto:olug-request at olug.org?subject=subscribe>
Sender: olug-bounces at olug.org
Errors-To: olug-bounces at olug.org
X-PMX-Version: 4.1.0.80455
Return-Path: olug-bounces at olug.org
X-OriginalArrivalTime: 25 Nov 2003 18:22:11.0893 (UTC) FILETIME=[0B574E50:01C3B381]

I sort of know what sed can do and have actually used code snips (aquired
from various places - like the one Brian just posted), but haven't sat down
to actually google / read man pages / etc.

Does anyone have/know of a 'one sheeter' that kinda gives an intro to sed
and awk somewhere?  How they kinda work, the idea behind, where to use and
where not to...

-t 


PS sorry about the post that basically repeated Terry's solution, for some
reason some mail was lagging on delivery...


-----Original Message-----
From: olug-bounces at olug.org [mailto:olug-bounces at olug.org] On Behalf Of
Brian Roberson
Sent: Tuesday, November 25, 2003 11:21 AM
To: Omaha Linux User Group
Subject: [OT] - subthread - perl vs sed Re: [olug] Text search and Replace 

While I am a huge fan of perl, I must say that it is overkill on things like
this, say you had directory with 50,000 files... just think about spawning
perl 50,000 time's vice sed plus the overhead that perl would add if the
files where 10Mb+ in size. AFAIK - perl would load 10Mb into resident mem
before even doing the substitution. sed uses the file control function fseek
when you give it a filename instead of standard out.


-- just an observation :)




----- Original Message ----- 
From: "Terry" <td3201 at yahoo.com>
To: <jnorton at jggt.com>; "Omaha Linux User Group" <olug at olug.org>
Sent: Tuesday, November 25, 2003 10:52 AM
Subject: Re: [olug] Text search and Replace


> lots of ways to do it, here is a 1-liner for you:
> perl -i.backup -pe 's/foo/bar/' filename
>
> you can write a loop around this easy enough in bash
> to go through all files in a directory.
>
> This replaces all occurrences of foo with bar.  You
> might need to tack on a g at the end of the regexp but
> I don't think so.
>
> --- Jeff Norton <jnorton at jggt.com> wrote:
> > I want to search a directory on my computer and
> > replace certain text
> > within documents with a new text.
> >
> > _______________________________________________
> > OLUG mailing list
> > OLUG at olug.org
> > http://lists.olug.org/mailman/listinfo/olug
>
>
> =====
> Terry
>
> __________________________________
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
> http://antispam.yahoo.com/whatsnewfree
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>

_______________________________________________
OLUG mailing list
OLUG at olug.org
http://lists.olug.org/mailman/listinfo/olug

_______________________________________________
OLUG mailing list
OLUG at olug.org
http://lists.olug.org/mailman/listinfo/olug


More information about the OLUG mailing list