Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing text

Status
Not open for further replies.

darfader

Programmer
Aug 6, 2003
38
GB
Hi,

what is the syntax for replacing text please ?

it's something like /%S/ipnet/telex

but I cannot find it in the man pages

$ man /
No manual entry for /.
$ man pattern
No manual entry for pattern.
$ man substituion
No manual entry for substituion.
$ man matching
No manual entry for matching.


tia,
 
man regexp

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
where are you replacing, what type of script? what language?

from command line:
echo &quot;String you want something replaced with&quot; | sed 's/thing to change/string to change to/g'

from perl:
$var=&quot;String you want something replaced with&quot; ;
$var~=s/thing to change/string to change to/g

etc...
 
its in vi

I want to replace a string with a string like this

/%S/ipnet/telex

but I haven't got it to work :(

 
:g/<string to find>/s//<string to replace>/g

:g <-- Globallay through the document
/<string to find>/ <-- find this string
s//<string to replace>/ <-- replace the aforementioned string
g <-- globally on this line

does that help?
 
Obviusly: man vi ...
What do you want to do ?
Change the word &quot;ipnet&quot; by the word &quot;telex&quot; on the line containing &quot;%S&quot; ?
If so then try this:
Code:
:/%S/s/ipnet/telex/
Otherwise, position your cursor on the line to modify and type this:
Code:
:s/ipnet/telex/

Hope This Help
PH.
 
jad & PH:

isn't English wonderful !

I am amazed how one question can be interpreted so many different ways ;)

I thought the command I wanted began /%S/target/replacement from some time ago, after looking in man vi and not finding it, I decided to ask here, now to what I want is, to parse through a text file finding all occurances of target and replacing it with replacement

thank you both for your suggestions
 
:g/<string to find>/s//<string to replace>/g

as i said before.

probably:

Code:
:g/ipnet/s//telex/g
 
Try someting like this in vi:
Code:
:1,$s/ipnet/telex/g

Hope This Help
PH.
 
Or you can do ..

:%s /ipnet/telex/g

Which I think is what you were trying to do originally.
Matt.
 
yes your'e right

all three work and this

<:%s /ipnet/telex/g>

was what I was trying to remember,


ty :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top