FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 03-04-2009, 10:11 PM
Emanoil Kotsev
 
Default OT: matched string of a regular expression

H.S. wrote:

> Then
> $> sed -e 's/(a(.*))1b/123b/' foo.dat > foo_new.dat
>
> Or just:
> $> sed -e 's/1b/23b/' foo.dat > foo_new.dat
>
> if only 1b is to be replaced. Same thing using perl (will replace
> contents of foo.dat inplace):
> $> perl -p -i -e "s/1b/23b/g;" foo.dat
>
>
> Regards

perl offers also forward backward lookup in regex, which makes it very
flexible.

(?: REGEXP ) Like (REGEXP) but does not make back-references.

(?= REGEXP ) Zero width positive look-ahead assertion.

(?! REGEXP ) Zero width negative look-ahead assertion.

http://networking.ringofsaturn.com/Unix/regex.php


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-04-2009, 10:27 PM
Tzafrir Cohen
 
Default OT: matched string of a regular expression

On Wed, Mar 04, 2009 at 04:24:27PM -0500, kamaraju kusumanchi wrote:

> Because of the size of the files involved, the number of files on
> which I have to perform this operation I decided to use sed (instead
> of doing it manually in vim)

Do this *manually* in vim?

There were suggestions for a number of sed one-liners. Those seem to
work in vim as well.

Just prefix them with :%

You may also consider a c alongside the g in the end to confirm
substitutions. Although in many cases the ability to undo is good
enough.

--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 03-15-2009, 12:36 AM
Kamaraju S Kusumanchi
 
Default OT: matched string of a regular expression

Florian Kulzer wrote:

> On Wed, Mar 04, 2009 at 16:24:27 -0500, kamaraju kusumanchi wrote:
>
> [...]
>
>> Now,
>> I would like to replace all the occurrences of
>>
>> a(ijk)1b with a(ijk)23b
>> a(jik)1b with a(jik)23b
>> a(ikj)1b with a(ikj)23b
>> and so on for all the strings such as a(???)
>>
>> Because of the size of the files involved, the number of files on
>> which I have to perform this operation I decided to use sed (instead
>> of doing it manually in vim)
>
> [...]
>
>> Is there any way
>> to write something like
>>
>> s/a(???)1b/a(???)23b/g
>>
>> where the second ??? is the string matched by the first regular
>> expression.
>
> sed -e 's/a((...))1b/a(1)23b/g'
>

You hit it right on the head. The 1 construct is exactly what I am after.
Thanks!

BTW, If anyone is interested, I found this great book called sed & awk (2nd
Edition), by Dale Dougherty, Arnold Robbins
http://www.amazon.com/sed-awk-2nd-Dale-Dougherty/dp/1565922255/ . It's so
far the best documentation I read on sed, awk. It also has lots of
practical tips.

raju
--
Kamaraju S Kusumanchi
http://malayamaarutham.blogspot.com/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 01:31 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org