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
sed with special characters itzz.me Shell Programming and Scripting 4 04-06-2009 09:34 PM
get rid of special characters vakharia Mahesh UNIX and Linux Applications 4 07-29-2008 01:36 PM
Array with special Characters donaldfung UNIX for Dummies Questions & Answers 1 06-08-2008 12:18 PM
special characters nawnaw UNIX for Dummies Questions & Answers 2 05-18-2004 03:17 PM
awk/sed with special characters apalex Shell Programming and Scripting 5 05-06-2002 04:40 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2009
ScKaSx ScKaSx is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 17
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.
  #2 (permalink)  
Old 06-24-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
:g/\\begin{work}/d
  #3 (permalink)  
Old 06-24-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
\ 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/.*/ /"
  #4 (permalink)  
Old 06-24-2009
ScKaSx ScKaSx is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 17
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 04:37 PM..
  #5 (permalink)  
Old 06-24-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
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 {}/%/
  #6 (permalink)  
Old 06-24-2009
ScKaSx ScKaSx is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 17
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
  #7 (permalink)  
Old 06-24-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
escape the \ with a \

:%s/\\begin {}/%/
Sponsored Links
Reply

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 09:19 PM.


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