![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 !! |
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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|