Hi All,
I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text.
An example of 4 lines in my file is:
1. MatchText_randomNumberOfText moreData ReplaceMe moreData
2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
I'm trying to create a bash script that takes a URL as one of its arguments like this:
./script.sh http://url.cfm?asdf&asdf=234
variable=$1
echo $variable
I'm having trouble storing the URL because it contains the meta character "&" which is being interpreted... thus when I run the... (4 Replies)
Hi All,
I have the following data in a korn shell variable:
a="FirstValue|SecondValue|ThirdValue"
The value between "FirstValue", "SecondValue" and "ThirdValue" can change, in this case is a comma: "," and I need to print it only once. I need to know what is the separator value.
I... (3 Replies)
I'm working on a different stage of a project that someone helped me address elsewhere in these threads.
The .docs I'm cycling through look roughly like this:
1 of 26 DOCUMENTS
Copyright 2010 The Age Company Limited
All Rights Reserved
The Age (Melbourne, Australia)
November 27, 2010... (9 Replies)
I have a file that contains the 2 following lines (from /proc/mounts)
/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
I need to match the string in the second column exactly so that only one result is returned, e.g.
> grep... (2 Replies)
I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios.
Cat test
Nov 10, 2012 5:17:53 AM
INFO: Request Type
Line 1.... (5 Replies)
Hi All,
I'm trying to view data using cut command for a fixed length file using the below command:
cut -c 1-3,4-5 FALCON_PIS_00000000.dat
I want to mention a separator say | (pipe) in between 1-3 and 4-5.
Please let me know how to achieve this.
Thanks in Advance, (3 Replies)
Hi,
Need your help for this scripting issue I have. I am not really good at this, so seeking your help.
I have a file looking similar to this:
Hello, i am human and name=ABCD.
How are you?
Hello, i am human and name=PQRS.
I am good.
Hello, i am human and name=ABCD.
Good bye.
Hello, i... (12 Replies)
Hello to all,
Please some help on this. I have the file in format as below.
How can I set the record separator as the string below in red
"No. Time Source Destination Protocol Length Info"
I've tried code below but it doesn't seem to... (6 Replies)
Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried:
grep -lr "this string" *
but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies
LEARN ABOUT PHP
levenshtein
LEVENSHTEIN(3) 1 LEVENSHTEIN(3)levenshtein - Calculate Levenshtein distance between two stringsSYNOPSIS
int levenshtein (string $str1, string $str2)
DESCRIPTION
int levenshtein (string $str1, string $str2, int $cost_ins, int $cost_rep, int $cost_del)
The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform $str1 into
$str2. The complexity of the algorithm is O(m*n), where n and m are the length of $str1 and $str2 (rather good when compared to simi-
lar_text(3), which is O(max(n,m)**3), but still expensive).
In its simplest form the function will take only the two strings as parameter and will calculate just the number of insert, replace and
delete operations needed to transform $str1 into $str2.
A second variant will take three additional parameters that define the cost of insert, replace and delete operations. This is more general
and adaptive than variant one, but not as efficient.
PARAMETERS
o $str1
- One of the strings being evaluated for Levenshtein distance.
o $str2
- One of the strings being evaluated for Levenshtein distance.
o $cost_ins
- Defines the cost of insertion.
o $cost_rep
- Defines the cost of replacement.
o $cost_del
- Defines the cost of deletion.
RETURN VALUES
This function returns the Levenshtein-Distance between the two argument strings or -1, if one of the argument strings is longer than the
limit of 255 characters.
EXAMPLES
Example #1
levenshtein(3) example
<?php
// input misspelled word
$input = 'carrrot';
// array of words to check against
$words = array('apple','pineapple','banana','orange',
'radish','carrot','pea','bean','potato');
// no shortest distance found, yet
$shortest = -1;
// loop through words to find the closest
foreach ($words as $word) {
// calculate the distance between the input word,
// and the current word
$lev = levenshtein($input, $word);
// check for an exact match
if ($lev == 0) {
// closest word is this one (exact match)
$closest = $word;
$shortest = 0;
// break out of the loop; we've found an exact match
break;
}
// if this distance is less than the next found shortest
// distance, OR if a next shortest word has not yet been found
if ($lev <= $shortest || $shortest < 0) {
// set the closest match, and shortest distance
$closest = $word;
$shortest = $lev;
}
}
echo "Input word: $input
";
if ($shortest == 0) {
echo "Exact match found: $closest
";
} else {
echo "Did you mean: $closest?
";
}
?>
The above example will output:
Input word: carrrot
Did you mean: carrot?
SEE ALSO soundex(3), similar_text(3), metaphone(3).
PHP Documentation Group LEVENSHTEIN(3)