I would like to comment a line that matched a string "sreenivas" in a file without opening it.
This won't work, because to find out if there is such line you will definitely have to open it somehow.
If you mean "without interactively opening" and assuming you use "#" as a comment sign (beware - there are some formats with other comment signs), try:
HI all
I am working on a script, few details are as follows. I have one properties File and one script. The property file contains the JOBID which are to be executed and the Script runs these jobs ONE by ONE. After completing the JOB I need to comment that job in the property File. This is the... (3 Replies)
All,
Is there any way out to display the nth line before the string is matched ???
Eg : If i have a file which has the following contents and if i want to get the
3rd line before the string is matched
a
b
c
d
e
f
if i give the input as f and lines before the match as 3 then it should... (5 Replies)
i have been doing this script to match every line in a current log file (access_log) with strings that i list from a path (consist of 100 of user's name ex: meggae )..
and then make a directory of every string from the text file (/path/meggae/) --->if it matched..
then print every line from the... (3 Replies)
Hi,
I have a query as follows :
suppose I am matching a string in a file say "start from here"
and I want to pick up 'n' number of lines () from the matched string. Is there any way to do that ?
1) going forward I want to do this for every match for the above string
2) or limit this to... (2 Replies)
Hi Experts,
Help needed on joining one line above & below to the pattern matched string line.
The input file, required output is mentioned below
Input file
ABCD DEFG5 42.0.1-63.38.31
KKKK iokl IP Connection Available
ABCD DEFG5 42.0.1-63.38.31
... (7 Replies)
Hi,
I have a file whose lines are something like
Tchampionspsq^@~^@^^^A^@^@^@^A^A^Aÿð^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^?ð^@^@^@^@^@^@^@?ð^@^@^@^@^@^@pppsq^@~^@#@^@^@^@^@^@^Hw^H^@^@^@^K^@^@^@^@xp^At^@^FTtime2psq^@ ~^@^^^A^@^@^@^B^A
I need to extract all words matching T*psq from the file.
Thing is... (4 Replies)
Hello All,
I have following file contents
cat file
#line=aaaaaa
#line=bbbbbb
#line=cccccc
#line=dddddd
line=eeeeee
#comment=11111
#comment=22222
#comment=33333
#comment=44444
comment=55555
Testing script
Good Luck!
I would like to comment line line=eeeeee and insert a new line... (19 Replies)
hi gurus,
I would like to be able to use awk to process 1 file as such:
abc 1 2 3 4 5 6 7 8 9 10
flags 1 2 4
flags 1 2 5
abc 2 3 4 5 6 7 8 9 10 11
flags 1 2 3
abc 4 5 6 7 8 9 6 7 78 89
flags 1 2 3
flags 1 2 4
flags 1 2 3 4
I would like to be able to print field 1 and 5 when the... (4 Replies)
Hello,
I know there are many questions and replies regarding grep command.
What I would like to do is a bit different.
File A:
hello world welcome to my page
this is my test site
how are you
I am fine, thank you
where have you been
I was in hospital
really hope you are fine now
Thanks,... (10 Replies)
Discussion started by: baris35
10 Replies
LEARN ABOUT PHP
ereg
EREG(3) 1 EREG(3)ereg - Regular expression matchSYNOPSIS
int ereg (string $pattern, string $string, [array &$regs])
DESCRIPTION
Searches a $string for matches to the regular expression given in $pattern in a case-sensitive way.
Warning
This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.
PARAMETERS
o $pattern
- Case sensitive regular expression.
o $string
- The input string.
o $regs
- If matches are found for parenthesized substrings of $pattern and the function is called with the third argument $regs, the
matches will be stored in the elements of the array $regs. $regs[1] will contain the substring which starts at the first left
parenthesis; $regs[2] will contain the substring starting at the second, and so on. $regs[0] will contain a copy of the complete
string matched.
RETURN VALUES
Returns the length of the matched string if a match for $pattern was found in $string, or FALSE if no matches were found or an error
occurred.
If the optional parameter $regs was not passed or the length of the matched string is 0, this function returns 1.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 4.1.0 | |
| | |
| | Up to (and including) PHP 4.1.0 $regs will be |
| | filled with exactly ten elements, even though |
| | more or fewer than ten parenthesized substrings |
| | may actually have matched. This has no effect on |
| | ereg(3)'s ability to match more substrings. If no |
| | matches are found, $regs will not be altered by |
| | ereg(3). |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
ereg(3) example
The following code snippet takes a date in ISO format (YYYY-MM-DD) and prints it in DD.MM.YYYY format:
<?php
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
?>
NOTES
Note
As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension. Calling this function will issue an E_DEPRECATED
notice. See the list of differences for help on converting to PCRE.
Tip
ereg(3) is deprecated as of PHP 5.3.0. preg_match(3) is the suggested alternative to this function.
SEE ALSO eregi(3), ereg_replace(3), eregi_replace(3), preg_match(3), strpos(3), strstr(3), quotemeta(3).
PHP Documentation Group EREG(3)