Save as filter.pl Run as perl filter.pl april_2015.txt
or perl filter.pl april_2015.txt > permanent.txt
or perl filter.pl april_2015.txt may_2015.txt june_2015.txt > permanent.txt
or perl filter.pl *_2015.txt > permanent.txt
hi experts(novice people can stay away as it is no child's game),
i am developing a script which works like recycle bin of windows.
the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (1 Reply)
hi experts(novice people can stay away as it is no child's game),
i am developing a script which works like recycle bin of windows.
the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (5 Replies)
Hi,
Does anyone know how to make BASH provide a list of possible completions on the first tab, and then start cycling through the possibilites on the next tab?
Right now this is what I have in my .bashrc:
bind "set show-all-if-ambiguous on"
bind \\C-o:menu-complete
This allows... (0 Replies)
Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string.
Previously, I was outputting just each paragraph with that search string with:
cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Suppose I have a file which contains other file names with some extention .
text file containt
gdsds sd8ef g/f/temp_temp.sum yyeta t/unix.sum
ghfp hrwer h/y/test.text.dat
if then....
I want to get the complete file names, like for above file I should get output as
temp_temp.sum... (4 Replies)
Hi,
I'm unable to execute the below command completely ; it's not allowing me to type the complete command. It is allowing till "xargs" and i cannot even press enter after that.
I'm using Solaris. Let me know if anything needs to be added so as to execute the complete command. Appreciate... (12 Replies)
Hi,
Below is my find command
find /opt/app/websphere -name myfolder -perm -600 | wc -l
At time it even takes 20 mins to complete.
my OS is : SunOS mypc 5.10 Generic_150400-09 sun4v sparc SUNW,T5440 (10 Replies)
I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules.
I would like to extract out and write to another file only the... (2 Replies)
Discussion started by: Egy
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)