Substitue 'Special Characters' in VI


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Substitue 'Special Characters' in VI
# 1  
Old 06-24-2009
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  
Old 06-24-2009
Code:
:g/\\begin{work}/d

# 3  
Old 06-24-2009
\ 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  
Old 06-24-2009
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..
# 5  
Old 06-24-2009
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  
Old 06-24-2009
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  
Old 06-24-2009
escape the \ with a \

:%s/\\begin {}/%/
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed substitue whole file + 1 substitue with variables on one sed line?.

I'm trying to remove '--X' from the whole file and using variables replace $oldvar with $newvar. I have tried with double quotes but it doesn't seem to work. $newvar is set to /usr/bin/bash. Would appreciate some guidance. newvar=$(which bash) oldvar=/bin/bash sed... (1 Reply)
Discussion started by: itman73
1 Replies

2. Shell Programming and Scripting

How to convert special characters?

Hi All, I have some text including Turkish characters and the 3rd party application that reads my file does not supporting this character set (at least, I have no control on it). So, I used below conversion for maximum character support but still have problems with "İ" and "Ş". Application... (5 Replies)
Discussion started by: mrcrowley
5 Replies

3. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

4. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

5. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

6. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

7. Shell Programming and Scripting

sed with special characters

Hi, I am reading a file (GC_JAR.log) which has entries like: 511725.629, 0.1122672 secs] 525268.975, 0.1240036 secs] 527181.835, 0.2068215 secs] 527914.287, 0.2884801 secs] 528457.134, 0.2548725 secs] I want to replace all the entries of "secs]" with just "secs" Thus, the output... (4 Replies)
Discussion started by: itzz.me
4 Replies

8. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 Replies

9. UNIX for Dummies Questions & Answers

Quoting of special characters

Hello, I am getting very confused as to where should i quote special/metacharacters in shell. Sometimes i write * directly and it works, othertimes i have to do "*". Same is the case with other special characters like /,\,.,$,etc. Can somebody give me link to somewhere where i can found... (1 Reply)
Discussion started by: vibhor_agarwali
1 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question