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
In Help, Substitute Text ... solidhelix08 Shell Programming and Scripting 6 02-07-2008 05:21 AM
rm substitute with blacklist broli UNIX for Dummies Questions & Answers 2 12-06-2007 08:13 AM
Substitute Variable mmg2711 UNIX for Dummies Questions & Answers 0 10-26-2007 06:59 AM
Substitute File name vanand420 Shell Programming and Scripting 22 03-14-2007 02:40 AM
vi + regexp + substitute Lomic UNIX for Dummies Questions & Answers 9 12-10-2004 10:50 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 Rate Thread Display Modes
  #1 (permalink)  
Old 01-11-2007
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
Substitute in vi

I know in vi you can do

:%s/replaceme/withthis/

but if i want to find all lines say without a # at the begining and I want to put it in how would that command be formatted? I can't figure it out for the life of me.

#comment
blah1
hey1
grrr1

#comment
#blah1
#hey1
#grrr1
  #2 (permalink)  
Old 01-11-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
:/^[^#]/s/replaceme/withthis/
  #3 (permalink)  
Old 01-16-2007
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
i can't get it to work what do i need to put into the /s to get this to work....been trying everything
  #4 (permalink)  
Old 01-16-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by kingdbag
i can't get it to work what do i need to put into the /s to get this to work....been trying everything
this is NOT helping us to help you....
  #5 (permalink)  
Old 01-16-2007
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
Code:
:%s/replaceme/withthis/
Change to.

Code:
:%s/^\([^#]\)/#\1/

You should lookup regular expressions. The ^ character matches "beginning of line". The square brackets define a character class. Basically, it means, "match any character in the square brackets". The ^ character has a special meaning inside the character class only if it's the 1st character in the character class. It means NOT.

So this means " find any line that starts with anything except a '#' character, and replace that character with a '#' character ".

The parentheses "capture" a regular expression match. In vi, they must be escaped so that vi knows you want to capture, instead of trying to match the parentheses. The \1 notation in the replacement string means replace with the 1st "captured" match.
  #6 (permalink)  
Old 01-17-2007
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
thanks for the help...
Closed Thread

Bookmarks

Tags
regex, regular expressions

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 12:43 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