To:
/directoryname1/subdirectoryname1/
/directoryname2/subdirectoryname2/
I could not trigger the beginning of the string as they varies. Right now,
I'm using SED to try and catch /*.txt and repalce it with nothing but i don't seem to get it to work.
Outputs:
/var/tmp/123
Outputs:
/var/tmp/123.txt (does nothing)
I'm just tyring to replace "/*.txt" to " "(nothing). Hope you guys can help me on that.
Thanks in advance.
i have this script that searches for a pattern.
However it fails if the pattern includes some
special characters. So far, it fails with the
following strings:
1. -Cr
2. $Mj
3. H'412
would a sed or awk be more effective?
i don't want the users to put the (\)
during the search (they... (5 Replies)
Hi. Does anyone know how to use the sed command to change the special border characters on this .per file. I have to edit about 80 .per files. I need a sed script to change the below 3 and A characters.
ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Test Islands, Office of Public Health -- WIC... (4 Replies)
Hello,
I have a file with many lines with below format:
\abc\\1234
jkl\\567
def\\345
\pqr\\567
\xyz\\234
Here, i need to do 2 things.
1. replace \\ with \
2. remove starting \
so output to be as below: (11 Replies)
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)
Hi everyone
I have file1 contains:
'7832'
' 8765
6543
I want a sed command that will format as:
'7832' , '8765' , '6543'
I tried
sed -e s/\'//g -e 's/^*//;s/*$//' file1 > file2
sed -e :a -e '$!N; s/\n/ /; ta' file2
which gives: 7832 8765 6543
I need some help to continue with... (5 Replies)
Hello All
Seeking the right one SED command.
My attempt is:
From orginal.txt by SED to target.txt
sed -i "/('outbound-callerid/a\$ext->add($context, $exten, '', new ext_SipAddHeader('P-Preferred-Identity', '<sip:${CALLERID(nummer)}@carrier.com>'));" orginal.txtWhat am make wrong?:wall:
... (5 Replies)
Need help in escaping special characters in sed command.
Here is the the string which i am trying to find a replace with
From :- REQUEST_TYPE=PIXEL&MSG_ID={//MESSAGE_ID}
To :- REQUEST_TYPE=PIXEL&MSG_ID= X_EDELIVERY_MESSAGE_ID & BATCH_ID= X_EDELIVERY_BATCH_ID
Here is the sed command i am... (2 Replies)
I am dusting off the sed cobwebs and had a basic question:
I have a file that contains:
$firewall = "on";
$cache = "on";
$dataset{'mary had a little lamb'} = "on";
and want to only change the contents of what is between the single quotes:
$dataset{'big bad wolf'} = "on";
I... (3 Replies)
I have the foolowing data file:
File1
<p name="A">5004</p>
<p name="B">5004</p>
<p name="C">5004</p>
<p name="A">15004</p>
<p name="B">15004</p>
<p name="C">15004</p>
In a while loop using sed (100 of line need to be replace), I need the output to File3:... (2 Replies)
Discussion started by: bobo
2 Replies
LEARN ABOUT PHP
stream_filter_register
STREAM_FILTER_REGISTER(3) 1 STREAM_FILTER_REGISTER(3)stream_filter_register - Register a user defined stream filterSYNOPSIS
bool stream_filter_register (string $filtername, string $classname)
DESCRIPTION stream_filter_register(3) allows you to implement your own filter on any registered stream used with all the other filesystem functions
(such as fopen(3), fread(3) etc.).
PARAMETERS
o $filtername
- The filter name to be registered.
o $classname
- To implement a filter, you need to define a class as an extension of php_user_filter with a number of member functions. When
performing read/write operations on the stream to which your filter is attached, PHP will pass the data through your filter (and
any other filters attached to that stream) so that the data may be modified as desired. You must implement the methods exactly as
described in php_user_filter - doing otherwise will lead to undefined behaviour.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
stream_filter_register(3) will return FALSE if the $filtername is already defined.
EXAMPLES
Example #1
Filter for capitalizing characters on foo-bar.txt stream
The example below implements a filter named strtoupper on the foo-bar.txt stream which will capitalize all letter characters writ-
ten to/read from that stream.
<?php
/* Define our filter class */
class strtoupper_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
/* Register our filter with PHP */
stream_filter_register("strtoupper", "strtoupper_filter")
or die("Failed to register filter");
$fp = fopen("foo-bar.txt", "w");
/* Attach the registered filter to the stream just opened */
stream_filter_append($fp, "strtoupper");
fwrite($fp, "Line1
");
fwrite($fp, "Word - 2
");
fwrite($fp, "Easy As 123
");
fclose($fp);
/* Read the contents back out
*/
readfile("foo-bar.txt");
?>
The above example will output:
LINE1
WORD - 2
EASY AS 123
Example #2
Registering a generic filter class to match multiple filter names.
<?php
/* Define our filter class */
class string_filter extends php_user_filter {
var $mode;
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
if ($this->mode == 1) {
$bucket->data = strtoupper($bucket->data);
} elseif ($this->mode == 0) {
$bucket->data = strtolower($bucket->data);
}
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
function onCreate()
{
if ($this->filtername == 'str.toupper') {
$this->mode = 1;
} elseif ($this->filtername == 'str.tolower') {
$this->mode = 0;
} else {
/* Some other str.* filter was asked for,
report failure so that PHP will keep looking */
return false;
}
return true;
}
}
/* Register our filter with PHP */
stream_filter_register("str.*", "string_filter")
or die("Failed to register filter");
$fp = fopen("foo-bar.txt", "w");
/* Attach the registered filter to the stream just opened
We could alternately bind to str.tolower here */
stream_filter_append($fp, "str.toupper");
fwrite($fp, "Line1
");
fwrite($fp, "Word - 2
");
fwrite($fp, "Easy As 123
");
fclose($fp);
/* Read the contents back out
*/
readfile("foo-bar.txt");
?>
The above example will output:
LINE1
WORD - 2
EASY AS 123
SEE ALSO stream_wrapper_register(3), stream_filter_append(3), stream_filter_prepend(3).
PHP Documentation Group STREAM_FILTER_REGISTER(3)