Sponsored Content
Full Discussion: line count
Top Forums Shell Programming and Scripting line count Post 302446190 by j_panky on Wednesday 18th of August 2010 03:35:56 AM
Old 08-18-2010
sorry but iam confused, as grep gives different output compare to awk...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get the line count from 2nd line of the file ?

Hi, I want to get the line count of the file from the 2nd line of the file ? The first line is header so want to skip that. Thanks. (8 Replies)
Discussion started by: smc3
8 Replies

2. UNIX for Dummies Questions & Answers

Count on every other line

I'd like to create a loop that will display something like: 1 2 29 2 57 2 ... 25173 2 I figure I'd want to make some code that counts to 1798 and for the odd numbers displays: 1+28((n-1)/2) and for the even numbers displays 2. This is what I wrote:#! /bin/csh #include <stdio.h> int... (4 Replies)
Discussion started by: red baron
4 Replies

3. Shell Programming and Scripting

Append line count to each line

Hello forum, I need to append the total line count to the end of each line in a file. The file where this line count needs to be appended is generated by this script: The script does a word frequency count by the first column of a file. if I add wc -l at the end then the line count... (4 Replies)
Discussion started by: jaysean
4 Replies

4. Shell Programming and Scripting

Line count

Hello friends, Could you please help on this, n=`wc -l test.txt` echo $n the above two line code give me "67 text.txt" where as i just need n= 67 as line count (3 Replies)
Discussion started by: Danish Shakil
3 Replies

5. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

6. Shell Programming and Scripting

Delimiter Count Line by Line

Hi All, I have totally 10 source files. I want to count the delimiter In my source files line by line and need to store the result in another file. I got the output for the total count of delimiter for one file. But I am struggling to get the delimiter count line by line for each my files. Plz... (6 Replies)
Discussion started by: suresh01_apk
6 Replies

7. Shell Programming and Scripting

line count

Hi In my directory i have file of many days , i want to count the number of line of all the files of todays date. every file will have date component on it for eg. V5_T_RIO_TAFM_20120905070015847.LOG from the file name 20120905- > this show that file is of today's date . I have written... (8 Replies)
Discussion started by: guddu_12
8 Replies

8. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

9. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

10. UNIX for Beginners Questions & Answers

Count pattern line by line

I have a file like below with more than 30,000 lines: Someword "mypattern blah blah mypattern blah mypattern blah " Someotherword "mypattern blah blah mypattern blah mypattern blah" Someword "mypattern blah blah blah mypattern blah " Someword "mypattern blah blah mypattern blah ... (3 Replies)
Discussion started by: ctrld
3 Replies
PREG_REPLACE_CALLBACK(3)						 1						  PREG_REPLACE_CALLBACK(3)

preg_replace_callback - Perform a regular expression search and replace using a callback

SYNOPSIS
mixed preg_replace_callback (mixed $pattern, callable $callback, mixed $subject, [int $limit = -1], [int &$count]) DESCRIPTION
The behavior of this function is almost identical to preg_replace(3), except for the fact that instead of $replacement parameter, one should specify a $callback. PARAMETERS
o $pattern - The pattern to search for. It can be either a string or an array with strings. o $callback - A callback that will be called and passed an array of matched elements in the $subject string. The callback should return the replacement string. This is the callback signature: string handler (array $matches) You'll often need the $callback function for a preg_replace_callback(3) in just one place. In this case you can use an anonymous function to declare the callback within the call to preg_replace_callback(3). By doing it this way you have all information for the call in one place and do not clutter the function namespace with a callback function's name not used anywhere else. Example #1 preg_replace_callback(3) and anonymous function <?php /* a unix-style command line filter to convert uppercase * letters at the beginning of paragraphs to lowercase */ $fp = fopen("php://stdin", "r") or die("can't read stdin"); while (!feof($fp)) { $line = fgets($fp); $line = preg_replace_callback( '|<p>s*w|', function ($matches) { return strtolower($matches[0]); }, $line ); echo $line; } fclose($fp); ?> o $subject - The string or an array with strings to search and replace. o $limit - The maximum possible replacements for each pattern in each $subject string. Defaults to -1 (no limit). o $count - If specified, this variable will be filled with the number of replacements done. RETURN VALUES
preg_replace_callback(3) returns an array if the $subject parameter is an array, or a string otherwise. On errors the return value is NULL If matches are found, the new subject will be returned, otherwise $subject will be returned unchanged. CHANGELOG
+--------+---------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------+ | 5.1.0 | | | | | | | The $count parameter was added | | | | +--------+---------------------------------+ EXAMPLES
Example #2 preg_replace_callback(3) example <?php // this text was used in 2002 // we want to get this up to date for 2003 $text = "April fools day is 04/01/2002 "; $text.= "Last christmas was 12/24/2001 "; // the callback function function next_year($matches) { // as usual: $matches[0] is the complete match // $matches[1] the match for the first subpattern // enclosed in '(...)' and so on return $matches[1].($matches[2]+1); } echo preg_replace_callback( "|(d{2}/d{2}/)(d{4})|", "next_year", $text); ?> The above example will output: April fools day is 04/01/2003 Last christmas was 12/24/2002 Example #3 preg_replace_callback(3) using recursive structure to handle encapsulated BB code <?php $input = "plain [indent] deep [indent] deeper [/indent] deep [/indent] plain"; function parseTagsRecursive($input) { $regex = '#[indent]((?:[^[]|[(?!/?indent])|(?R))+)[/indent]#'; if (is_array($input)) { $input = '<div style="margin-left: 10px">'.$input[1].'</div>'; } return preg_replace_callback($regex, 'parseTagsRecursive', $input); } $output = parseTagsRecursive($input); echo $output; ?> SEE ALSO
PCRE Patterns, preg_quote(3), preg_replace(3), preg_last_error(3), Anonymous functions, information about the callback type. PHP Documentation Group PREG_REPLACE_CALLBACK(3)
All times are GMT -4. The time now is 01:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy