![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| In Help, Substitute Text ... | solidhelix08 | Shell Programming and Scripting | 6 | 02-07-2008 02:21 AM |
| rm substitute with blacklist | broli | UNIX for Dummies Questions & Answers | 2 | 12-06-2007 05:13 AM |
| Substitute Variable | mmg2711 | UNIX for Dummies Questions & Answers | 0 | 10-26-2007 03:59 AM |
| Substitute File name | vanand420 | Shell Programming and Scripting | 22 | 03-13-2007 11:40 PM |
| vi + regexp + substitute | Lomic | UNIX for Dummies Questions & Answers | 9 | 12-10-2004 07:50 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
:/^[^#]/s/replaceme/withthis/ |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
|
|
#5
|
|||
|
|||
|
Code:
:%s/replaceme/withthis/ 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
|
|||
|
|||
|
thanks for the help...
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|