The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regexp help TinCanFury Shell Programming and Scripting 0 04-06-2008 06:21 PM
In Help, Substitute Text ... solidhelix08 Shell Programming and Scripting 6 02-07-2008 05:21 AM
regexp with sed again!!! andy2000 Shell Programming and Scripting 2 05-03-2007 10:15 AM
Substitute in vi kingdbag UNIX for Dummies Questions & Answers 5 01-17-2007 02:42 PM
regexp penfold UNIX for Advanced & Expert Users 1 06-28-2005 07:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 12-10-2004
Lomic Lomic is offline
Registered User
  
 

Join Date: Dec 2004
Location: Paris
Posts: 20
vi + regexp + substitute

Another enigma (for me)

Using VI I edit some files in which I want to erase many lines I don't need anymore

usually I do something like that:
Code:
:%s/line_to_suppress//g
and it is doing fine

but in this case, the pattern to erase contains some special characters

so I do it like that:
Code:
:%s#line_to_suppress_with_special_characters##g
but, the only problem left is that I can't predict what will be the beginning of the line so I wish I could do something like that:
Code:
:%s/*line_to_suppress//g
but of course if I protect the pattern with # to prevent special characters to annoy me... the * don't work anymore

the best way would be to suppress each line containing my pattern, but I don't know how to do that

I'm sure it's pretty easy for many among you, so if one have a bit of time, it would help me a lot

Thanx
  #2 (permalink)  
Old 12-10-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
I'm not too sure that I follow - but you can supress the interpretation of metacharacters by backslash escaping them...

e.g.
Code:
:%s/^.*my_patter_has_special_chars\*\/\$\^_in_it.*$//
As you can see, the .* at the beginning and end of line are still treated as metacharacters (as are the anchors).

Cheers
ZB
  #3 (permalink)  
Old 12-10-2004
Lomic Lomic is offline
Registered User
  
 

Join Date: Dec 2004
Location: Paris
Posts: 20
Quote:
Originally posted by zazzybob
you can supress the interpretation of metacharacters by backslash escaping them...

e.g.
Code:
:%s/^.*my_patter_has_special_chars\*\/\$\^_in_it.*$//
As you can see, the .* at the beginning and end of line are still treated as metacharacters (as are the anchors).
ok but my_pattern_has_special_chars looks like
Code:
blabla 'toto' rep:/titi/toto/
so I protect it between #

if I understand what you mean, I should do like this:
Code:
:%s/^.*blabla\ \'toto\'\ rep\:\/titi\/toto\///
Am I right? (if it is the case, it si ok because my pattern never change)
  #4 (permalink)  
Old 12-10-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Quote:
Originally posted by Lomic
if I understand what you mean, I should do like this:
Code:
:%s/^.*blabla\ \'toto\'\ rep\:\/titi\/toto\///
Am I right? (if it is the case, it si ok because my pattern never change)
Looking at that, all you really need to do is
Code:
:%s/^.*blabla 'toto' rep:\/titi\/toto\///
i.e. it's only the slashes that need to be escaped.

Cheers
ZB
  #5 (permalink)  
Old 12-10-2004
Lomic Lomic is offline
Registered User
  
 

Join Date: Dec 2004
Location: Paris
Posts: 20
Quote:
Originally posted by zazzybob
i.e. it's only the slashes that need to be escaped.
you're right, it is nearly ok now! (good step forward for me)

but one more question

it erase the lines, but it doesn't suppress them...

any hint?
  #6 (permalink)  
Old 12-10-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
What do you mean suppress?

Cheers
ZB
  #7 (permalink)  
Old 12-10-2004
Lomic Lomic is offline
Registered User
  
 

Join Date: Dec 2004
Location: Paris
Posts: 20
Quote:
Originally posted by zazzybob
What do you mean suppress?
File before:
xxxxxxxxxxx
xxxxxxxxxxx
blabla 'toto' rep:/titi/toto/
xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxx
blabla 'toto' rep:/titi/toto
/blabla 'toto' rep:/titi/toto/
xxxxxxxxxxx
blabla 'toto' rep:/titi/toto/
blabla 'toto' rep:/titi/toto/
xxxxxxxxxxx

File after:
xxxxxxxxxxx
xxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxx


xxxxxxxxxxx


xxxxxxxxxxx

Result I wish to have:
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxx

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0