as title said, Im trying to change only the first occurrence of word.By using
sed 's/this/that/' file.txt
though i'm not using g option it replace entire file. How to fix this.?
UPDATE:
$ cat file.txt
first line
this
this
this
this
$ sed -e '1s/this/that/;t' file.txt
first line
this // ------> I want to change only this "this" to "that" :)
this
this
this
is it possible to in-place replace the entire html document?
i tried jQuery("html").html("....")
but style information does not survive.
i'm trying to avoid using data uri because i do not want the generated document to be stored in the browsers history
hi~
all DLLs and EXEs in Symbian goes to sys\bin folder, right?
does system DLLs (build-in DLLs) in there too?
can i replace while install my own app?
thank you!
Hello, I have a table with OWN_ID and OWN_Email -
3ace7cf80edd | [email protected]
3acf6af33ff7 | [email protected]
3acda2524e00 | [email protected]
3ad75583c9a7 | [email protected]
3ad74b018999 | [email protected]
etc.
the problem is that it should contain only a single ID per Email, also I need to replace all OWN_ID values in another table by highest OWN_ID value of the OWN_Email
Is it possible to find and replace in selected text in Snow Leopard Xcode 3.2? There always use to be an option for selected text. Really frustrating. Thanks.
from XML
< NET ID="10.10.10.10, 255.255.255.0" /
I need to replace the text 10.10.10.10, 255.255.255.0
with 192.9.1.1, 255.0.0.0 by VB + DOM script
so the final line in the XML should be
< NET ID="192.9.1.1, 255.0.0.0" /
THX
I have this loop that runs in O(end - start) and I would like to replace it with something O(1).
If "width" wouldn't be decreasing, it would be pretty simple.
for (int i = start; i <= end; i++, width--)
if (i % 3 > 0) // 1 or 2, but not 0
z += width;
start, end and width have positive values
Need to replace a domain name on all the links on the page that are not images or pdf files.
This would be a full html page received through a proxy service.
I have a string;
text="Label"
and I need to replace it to:
text="{resourceManager.getString('trad', 'Label')}"
What would be the easiest expression to do this?
I want to disable all links within a div and replace it with the content that was there.
i.e.
<div><a href="/blah.html">My super link</a></div>
to
<div>My super link</div>
Thanks
EDIT
i have something like this in a file:
imagecolor=0
arrayimagecolorcopy=0
arrayimagecolorcopy3d=0
when i use sed -i -e 's/imagecolor=0/imagecolor=1/' it will change 1 and 2 line. But i only want it to replace first line.
i also tried sed with \< \ and \b \b, but no luck. Could it be the '=' sign? Do we have something like -w as in grep command?
Thank you.
UPDATE (see end of question)
The text "search and replace" utility programs I've seen, seem to only search on a line-by-line basis...
Is there a command-line tool which can locate one block of lines (in a text file), and replace it with another block of lines.?
For example: Does the test file file contain this exact group of lines:
'Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.
'Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!'
I want this, so that I can replace multiple lines of text in a file and know I'm not overwriting the wrong lines.
I would never replace "The Jabberwocky" (Lewis Carroll), but it makes a novel example :)
UPDATE:
..(sub-update) My following comment about reasons when not use sed are only in the context of; don't push any tool too far beyond its design intent (I use sed quite often, and consider it to be invaluable.)
I just now found an interesting web page about sed and when not to use it.
So, because of all the sed answers, I"ll post the link.. it is part of the sed FAQ on sourceforge
Also, I'm pretty sure there is some way diff can do the job of locating the block of text (once it's located, the replacement is quite straight foward; using head and tail) ... 'diff' dumps all the necessary data, but I haven't yet worked out how to filter it , ... (I'm still working on it)
I'm not sure if title sounds right actually, so I will give more explanation here.
I will begin from very beginning :)
I'm using c# and .net for my development.
I have an application that makes requests to some soap web-service and for each user request it produces 3 to 10 requests for web-service, they should all run async to finish in one time, so I use Async method of the web-service generated reference and then wait for result on callback. But it seems like it starts a thread (or takes it from pool) for every async call I make, so if I have 10 clients I got to spawn 30 to 100 threads and it sounds terrible even for my 16 cores server :) So i wanted to replace low level transport implementation with my own which uses non-blocking sockets and can handle at least 50 sockets run parallel in one thread with not much overhead. But I actually dunno where to put my override best.
I analyzed System.Web.Services.Protocols.SoapHttpClientProtocol class and see that it has some GetWebRequest method which I actually could use. If only I could somehow interupt the object it creates and get a http request with all headers and body from there and then send it with my own sockets..
Any ideas what approach to use? Or maybe there's something built in the framework I can use?
Hi there,
I have this
The body:
<body><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent leo leo, ultrices eu venenatis et, rutrum fringilla dolor.</p></body>
The code:
HtmlNode body = doc.DocumentNode.SelectSingleNode("//body");
Dictionary<HtmlNode, HtmlNode> toReplace = new Dictionary<HtmlNode, HtmlNode>();
// I do some logic here adding nodes to the toReplace dictionary.
foreach (HtmlNode replaceNode in toReplace.Keys)
{
replaceNode.ParentNod.ReplaceChild(toReplace[replaceNode], replaceNode);
}
After i do this, the InnerHtml of the body node remains the same as from beginning, although the OutterHtml or the InnerText are showing the good result. Is there something wrong with my code?
The result:
// body.InnerHtml
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent leo leo, ultrices eu venenatis et, rutrum fringilla dolor.</p>
// body.OutterHtml
<body><p>Lorem ipsum dolor sit amet...</p></body>
Hello !
I'm trying to extract some information from a webpage using php cURL+preg_match or any other function but for some reasons it doesn't work at all .
For example from this page http://www.foxtons.co.uk/search?location_ids=1001-29&property_id=712128&search_form=map&search_type=LL&submit_type=search
I want to extract the title which is "4 bed house to rent,
Caroline Place, Bayswater, W2", the price which is "2,300" and the description which starts at "This fantastic..." and ends at "(Circle and District Lines). "
I tried to use php cURL + dom but I'm getting a lot of errors like this "htmlParseEntityRef: expecting ';' in Entity, line: 243" and no result displayed
Also I tried to use preg_match or preg_match_all but doesn't work either .
A very basic example would be highly appreciated !
thank you !
Hello
I am applying the following function
<?php
function replaceChar($string){
$new_string = preg_replace("/[^a-zA-Z0-9\sçéèêëñòóôõöàáâäåìíîïùúûüýÿ]/", "", $string);
return $new_string;
}
$string = "This is some text and numbers 12345 and symbols !£%^#&$ and foreign letters éèêëñòóôõöàáâäåìíîïùúûüýÿ";
echo replaceChar($string);
?>
which works fine but if I add ã to the preg_replace like
$new_string = preg_replace("/[^a-zA-Z0-9\sçéèêëñòóôõöàáâãäåìíîïùúûüýÿ]/", "", $string);
$string = "This is some text and numbers 12345 and symbols !£%^#&$ and foreign letters éèêëñòóôõöàáâäåìíîïùúûüýÿã";
It conflicts with the pound sign £ and replaces the pound sign with the unidentified question mark in black square.
This is not critical but does anyone know why this is?
Thank you,
Barry
Hi all,
I'm using the function preg_replace but I cannot figure out how to make it work, the function just doesn't seem to work for me.
What I'm trying to do is to convert a string into a link if any word contains the % (percentage) character.
For instance if I have the string "go to %mysite", I'd like to convert the mysite word into a link.
I tried the following...
$data = "go to %mysite";
$result = preg_replace('/(^|[\s.\,\:\;]+)%([A-Za-z0-9]{1,64})/e', '\1%\2', $data);
...but it doesn't work.
Any help on this would be much appreciated.
Thanks
Juan
I'm reading out the mime types from IIS's MimeMap using the command
_mimeTypes = new Dictionary<string, string>();
//load from iis store.
DirectoryEntry Path = new DirectoryEntry("IIS://localhost/MimeMap");
PropertyValueCollection PropValues = Path.Properties["MimeMap"];
IISOle.MimeMap MimeTypeObj;
foreach (var item in PropValues)
{
// IISOle -> Add reference to Active DS IIS Namespace provider
MimeTypeObj = (IISOle.MimeMap)item;
_mimeTypes.Add(MimeTypeObj.Extension, MimeTypeObj.MimeType);
}
Do I need replace the localhost part when I deploy it to my live server? If not, why not and what are the implications of not doing so.
Cheers
I'm using a modal view controller to allow a user to select an address book entry and email address. The ABPeoplePickerNavigationController object is displayed via presentModalViewController:animated:
[self presentModalViewController:picker animated:YES];
What I want to do is keep the modal dialog up, but when the user selects the email address, it should cross-fade to a different controller that displays a message composition window.
I've tried various approaches in peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier: to dismiss the picker and set my custom composition controller as the modal view. I can do it any number of ways, but never does it fade smoothly from the picker to the composition controller -- unless I make the composition controller a modal dialog of the picker, in which case the picker re-appears when I dismiss the composition controller. I don't want that, either.
There must be some way to smoothly replace one controller and its view with another controller and its view, all within the context of a modal dialog, and preferably with a cross fade. Suggestions greatly appreciated.
I have a simple commenting system here...
http://affbuzz.com/comments/7299a55137def55917a5dc6c4fe0f261af8a4217
...and people can submit hyperlinks inside the plain text field. When I display these records back from the database and into the web page, what RegExp in PHP can I use to convert these links into HTML-type anchor links?
Bonus: For the algorithm to not do this with any other kind of link, just http and https.
I need to extract data from a source that presents it in one of two ways. The data could be formatted like this:
Francis (Lab) 18,077 (60.05%); Waller (LD) 4,140 (13.75%); Evans (PC) 3,545 (11.78%); Rees-Mogg (C) 3,064 (10.18%); Wright (Veritas) 768 (2.55%); La Vey (Green) 510 (1.69%)
Or like this:
Lab 8,994 (33.00%); C 7,924 (29.07%); LD 5,197 (19.07%); PC 3,818 (14.01%); Others 517 (1.90%); Green 512 (1.88%); UKIP 296 (1.09%)
The data I need to extract is the percentage and the party (these are election results), which is either in brackets (first example) or is the only non-numeric text.
So far I have this:
preg_match('/(.*)\(([^)]*)%\)/', $value, $match);
Which is giving me the following matches (for first example):
Array
(
[0] => Francis (Lab) 18,077 (60.05%)
[1] => Francis (Lab) 18,077
[2] => 60.05
)
So I have the percentage, but I also need the party label, which may or may not be in brackets and may or may not be the only text. Can anyone help?
How can i replace all > with > and < with < inside a <code> tag with ruby?
For example:
<code><script>alert('I steal cookies');</script></code>
With:
<code><script>alert('I steal cookies);<script><code>
The reason for this is because the h() method escapes all the < and >
Thanks, Micke