![]() |
|
|
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 |
| sed with special characters | itzz.me | Shell Programming and Scripting | 4 | 04-06-2009 10:34 PM |
| get rid of special characters | vakharia Mahesh | UNIX and Linux Applications | 4 | 07-29-2008 02:36 PM |
| Array with special Characters | donaldfung | UNIX for Dummies Questions & Answers | 1 | 06-08-2008 01:18 PM |
| special characters | nawnaw | UNIX for Dummies Questions & Answers | 2 | 05-18-2004 04:17 PM |
| awk/sed with special characters | apalex | Shell Programming and Scripting | 5 | 05-06-2002 05:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Substitue 'Special Characters' in VI
Hi All, I am using LATEX and need to delete all the lines in a file matching: \begin{work} I know there are several ways to do this, but I am trying to do it with the substitute command in VI. The problem is I can't get substitute to recognize the character '\'! How do I do it? Currently I am trying Code:
:%s/\([\begin{work}]\)/ /g
Thanks in advance, cheers. |
|
||||
|
\ has special meaning so you must escape it... Code:
:%s/\\([\\begin{work}]\\)/ /g
But the example you posted is not exactly the greatest... In the search you used \( ..... \) And in the substitution you said / / Which would ultimately replace everything with a space! So why not just say "s/.*/ /" |
|
||||
|
Thanks guys, afew more questions. Just curiousity but what is :g//d (is it part of substitution) As for the \(..\) that was a regular expression capture that I forgot to take out. As for the s/.*//g what do you mean? If instead of deleting \begin{} but rather replace it which say "%" what would be a good way of doing that with substitution? When I try Code:
:%s/\([\\item]\)/%/g it does what scottn says and replaces alot of things. I guess I'm alittle confused on the notation for regular expressions. Cheers Last edited by ScKaSx; 06-24-2009 at 05:37 PM.. |
|
||||
|
The notation can be confusing (it's alien, really). But it's worth learning. I thought I knew it pretty well, but some of the stuff I see here is really awesome. To answer your questions, I don't know what :g//d does. g generally means "global" and d "delete", but in the VI I'm using it doesn't work. You already know what \(...\) means, you said. s/.*//g means replace everything with nothing (where /.*/ means everything and // means nothing). To replace Code:
begin {}
With Code:
% Code:
:%s/begin {}/%/
|
|
||||
|
Thanks for the reply scottn,
however what I want to replace is "\begin{}" the thing that is giving me trouble is the "\" backslash which is used for many other things in vi. Actually the :g//d worked! but it deletes the whole line that contains the string. I just want to replace "\begin{}" with "%". These characters are killing me! Cheers, ScKaSx |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|