Results 1 to 4 of 4
Hi i'm brand new to the forum. I am taking a linux/unnix class at my school. The professor would like me to find and replace a phrase in a document ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-27-2010 #1
- Join Date
- Mar 2010
[SOLVED] College Class Help(vi)
Hi i'm brand new to the forum. I am taking a linux/unnix class at my school. The professor would like me to find and replace a phrase in a document he created for homework. However, the phrase is "all special characters!" he makes a note of it that we will have to escape the special characters in vi with \ and there should be 8 of them i use all 8 and it never works! I'm so confused!
**/**/** thats what we are to search for and replace with NEVER
so i've tried :1,$ s/*\*\/\*\*\/\*\*\/NEVER
and i get *\*\/\*\*\/\*\*\/NEVER pattern cant be found
then i tried :1,$ s/*\*\/\*\*\/\*\*\ /NEVER
and get :1,$ s/*\*\/\*\*\/\*\*\ can't be found
then i tried :1,$ s/\*\*\/\*\*\/\*\*\/NEVER
and once again get pattern can not be found
I just can't understand it because i'm using all 8 backslashes like he wants but i can never get it right. The only time i came close was when i messed up and i got all the stars to highlight but not the backslashes
he wants the entire phrase **/**/** changed to NEVER
for instance "Your mom **/**/** washes the dishes"
to "Your mom NEVER washes the dishes"
I know i'm brand new to this forum and I'm posting a question the day i registered but i really need some help and idk where else to go. And i'm so sorry if this question has already been answered somewhere else , I dont think i know what i'm looking for i searched for "escaping special characters" on here and google and just got a whole bunch of code and where not doing code till around the 12th week. I would really appreciate any help i'm so lost and confused
- 03-27-2010 #2
I'm not going to give you the answer because we don't do other people's homework question in this forum. However, I will give you some hints on how to work through this problem systematically.
First imagine that you wanted to change an ordinary word, without any special characters. For example, supposing you wanted to change "never" into "NEVER". How many slashes would you need to put in to satisfy the syntax requirements of the s command? Write it down on paper and look at it. Count the slashes and note where they go in relation to the input and output strings. Those slashes will appear in the final version in the same places and they won't be backslashed.
Now gradually replace your input string with special characters, making sure that each one is preceded by a backslash. You should gradually see how to do it."I'm just a little old lady; don't try to dazzle me with jargon!"
- 03-27-2010 #3
- Join Date
- Dec 2009
- Maryland, USA
I won't give you the answer, but none of the commands you tried is correct. I suggest this: Try writing the command without concern for the special characters, then add the escape, '\', before each special character.
- 03-27-2010 #4
- Join Date
- Mar 2010
well that was alot of help right there just to tell me that i needed the backslashes BEFORE the special characters...I will try all these methods and wait for my professor's email back on the exact same subject. I purposely put that it was a homework assignment so that you wouldn't give me the answer I could have easily just said I'm just messing around with vi, but i need to learn the process for an exam that i'll be taking online as soon as i finish this problem
worked like a charm thank you very much for that little bit of help! i've been thinking the whole time i needed to escape after the character thank you so much again
oh and for anyone else that may have the same problem i did my professor said this and it helped me understand it even more
"What the back slash is doing is telling the shell that the next character it will see, must be treated in
the opposite manner than it would if there wasn't a back slash."