I am looking to get a output of "2 apple found" from the awk command below.
black:34104 tomonorisoejima$ cat tomo
apple apple
black:34104 tomonorisoejima$ awk '/apple/ {count++}END{print count " apple found"}' tomo
1 apple found
black:34104 tomonorisoejima$ (5 Replies)
I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'.
Here's a portion of the text I'm trying to parse:
lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb
registrations:
key 4156 4353 0000 0000
... (3 Replies)
Hi
I have the following file
ENST001 ENST002 4 4 4 88 9 9
ENST004 3 3 3 99 8 8
ENST009 ENST010 ENST006 8 8 8 77 8 8
Basically I want to count how many times ENST* is repeated in each line so the expected results is
2
1
3
Any suggestion please ? (4 Replies)
Hi,
I am getting crazy after days on looking at it:
Bash in Ubuntu 12.04.1
I want to do this:
pattern="system /path1/file1 file1"
new_pattern=" data /path2/file2 file2"
file to edit: data.db
- I need to search in the file data.db for the nth occurrence of pattern
- pattern must... (14 Replies)
Given an XML file that contains (NOT "consists of"):
</dict>
<key>system.</key>
<dict>
<key>rule</key>
<string>default</string>
</dict>
<key>system.burn</key>
... (9 Replies)
Hi,
I have a file which contained a set of numbers like
Col1 col2 col3 col4
1 sa 13 0
2 sb 14 0
3 sc 15 9
4 sd 16 -9
5 sd 20 -2
6 sd 20 4
Here in last column I need to count the zeros, positive values and negative values,
please help me to do that. (2 Replies)
I need help with extract/print lines till stop pattern. This needs to happen after every 3rd occurrence of start pattern and continue till end of file. Consider below is an example of the log file. my start pattern will be every 3rd occurrence of ERROR_FILE_NOT_FOUND and stop pattern will be... (5 Replies)
Hi All,
let's say an input looks like:
C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11
----------------------------------
1|0123452|C501|Z|Z|Z|E|E|E|E|E|E|E
1|0156123|C501|X|X|X|E|E|E|E|E|E|E
1|0178903|C501|Z|Z|Z|E|E|E|E|E|E|E
1|0127896|C501|Z|Z|Z|E|E|E|E|E|E|E
1|0981678|C501|X|X|X|E|E|E|E|E|E|E
... (6 Replies)
Discussion started by: suresh_target
6 Replies
LEARN ABOUT PHP
array_walk
ARRAY_WALK(3) 1 ARRAY_WALK(3)array_walk - Apply a user supplied function to every member of an arraySYNOPSIS
bool array_walk NULL (array &$array, callable $callback, [mixed $userdata])
DESCRIPTION
Applies the user-defined $callback function to each element of the $array array.
array_walk(3) is not affected by the internal array pointer of $array. array_walk(3) will walk through the entire array regardless of
pointer position.
PARAMETERS
o $array
- The input array.
o $callback
- Typically, $callback takes on two parameters. The $array parameter's value being the first, and the key/index second.
Note
If $callback needs to be working with the actual values of the array, specify the first parameter of $callback as a refer-
ence. Then, any changes made to those elements will be made in the original array itself.
Note
Many internal functions (for example strtolower(3)) will throw a warning if more than the expected number of argument are
passed in and are not usable directly as a $callback.
Only the values of the $array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset
or reorder elements. If the callback does not respect this requirement, the behavior of this function is undefined, and unpre-
dictable.
o $userdata
- If the optional $userdata parameter is supplied, it will be passed as the third parameter to the $callback.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
ERRORS /EXCEPTIONS
If function $callback requires more parameters than given to it, an error of level E_WARNING will be generated each time array_walk(3)
calls $callback.
EXAMPLES
Example #1
array_walk(3) example
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
function test_alter(&$item1, $key, $prefix)
{
$item1 = "$prefix: $item1";
}
function test_print($item2, $key)
{
echo "$key. $item2<br />
";
}
echo "Before ...:
";
array_walk($fruits, 'test_print');
array_walk($fruits, 'test_alter', 'fruit');
echo "... and after:
";
array_walk($fruits, 'test_print');
?>
The above example will output:
Before ...:
d. lemon
a. orange
b. banana
c. apple
d. fruit: lemon
a. fruit: orange
b. fruit: banana
c. fruit: apple
SEE ALSO array_walk_recursive(3), iterator_apply(3), list(3), each(3), call_user_func_array(3), array_map(3), information about the callback type,
foreach.
PHP Documentation Group ARRAY_WALK(3)