hi all
I have a 2 files. both the files have some numbers and i want to find out each number in file1 is existing or not in file2. if not then put it into new file. if yes then also in a seperate file
i can not use diff command as the files are different and no order has been defined.
... (2 Replies)
Hi folks
I am not allowed to install GNU grep on AIX.
Here my code excerpt:
grep_fatal () {
/usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP"
}
Howto the same on AIX based machine?
from manual GNU grep
‘--after-context=num’
Print num lines of trailing context after... (4 Replies)
Hi,
I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using:
grep -w 'Possible network disconnect' file_name.
But I am more interested in getting the timing of these events which are... (7 Replies)
Hi,
I need to match up some numbers in one file to the closest numbers in other file and produce an output file.
File one (f1.txt) is laid out like this
PCode Lon Lat
AB10 1AA 57.148235 -2.096648
BB2 3JD 53.728563 -2.47852
LU4 9ET... (4 Replies)
Experts:
I don't know that regular expressions will ever be easy for me, so if one of you guru's could help out, I'd appreciate it.
I'm trying to match a line in our syslog, but I can't figure out how to match a number inside a bracket. This is what I'm trying to match.
"Jul 16 00:01:34... (2 Replies)
Hi All,
I have a file which looks like this:
abc 1
abc 2
abc 3
abc 4
abc 5
bcd 1
bcd 3
bcd 3
bcd 5
cde 7
This file is just a miniature version of what I really have. Original file is some 1 million lines long.
I have tried to come up with the code for what I wish to accomplish... (1 Reply)
Hi,
I have one file 1.txt with one field consist of following Ids (shortlisted 10 but showing 3 here):
00052
00184
00607
and then second file 2.txt with three fields (very big file):
00052 00184 12.73062
00052 00598 13.51205
00052 00599 13.92554
00052 00600 13.73358... (2 Replies)
Hi, I have text file:
Name: xyz
Gender: M
Address: "120_B_C; ksilskdj; lsudlfw"
Zip: 20392
Name: KLM
Gender: F
Address: "65_D_F; wnmlsi;lsuod;,...."
Zip:90233I want to insert 2 new lines before the 'Address: ' line deriving value from this Address line value
The Address value in quotes... (1 Reply)
Hello,
I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies
LEARN ABOUT PHP
substr
SUBSTR(3) 1 SUBSTR(3)substr - Return part of a stringSYNOPSIS
string substr (string $string, int $start, [int $length])
DESCRIPTION
Returns the portion of $string specified by the $start and $length parameters.
PARAMETERS
o $string
- The input string. Must be one character or longer.
o $start
- If $start is non-negative, the returned string will start at the $start'th position in $string, counting from zero. For
instance, in the string ' abcdef', the character at position 0 is ' a', the character at position 2 is ' c', and so forth. If
$start is negative, the returned string will start at the $start'th character from the end of $string. If $string is less than or
equal to $start characters long, FALSE will be returned.
Example #1
Using a negative $start
<?php
$rest = substr("abcdef", -1); // returns "f"
$rest = substr("abcdef", -2); // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
o $length
- If $length is given and is positive, the string returned will contain at most $length characters beginning from $start (depend-
ing on the length of $string). If $length is given and is negative, then that many characters will be omitted from the end of
$string (after the start position has been calculated when a $start is negative). If $start denotes the position of this trunca-
tion or beyond, false will be returned. If $length is given and is 0, FALSE or NULL, an empty string will be returned. If
$length is omitted, the substring starting from $start until the end of the string will be returned.
Example #2
Using a negative $length
<?php
$rest = substr("abcdef", 0, -1); // returns "abcde"
$rest = substr("abcdef", 2, -1); // returns "cde"
$rest = substr("abcdef", 4, -4); // returns false
$rest = substr("abcdef", -3, -1); // returns "de"
?>
RETURN VALUES
Returns the extracted part of $string; or FALSE on failure, or an empty string.
CHANGELOG
+--------------+---------------------------------------------------+
| Version | |
| | |
| | Description |
| | |
+--------------+---------------------------------------------------+
|5.2.2 - 5.2.6 | |
| | |
| | If the $start parameter indicates the position |
| | of a negative truncation or beyond, false is |
| | returned. Other versions get the string from |
| | start. |
| | |
+--------------+---------------------------------------------------+
EXAMPLES
Example #3
Basic substr(3) usage
<?php
echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f
// Accessing single characters in a string
// can also be achieved using "square brackets"
$string = 'abcdef';
echo $string[0]; // a
echo $string[3]; // d
echo $string[strlen($string)-1]; // f
?>
Example #4
substr(3) casting behaviour
<?php
class apple {
public function __toString() {
return "green";
}
}
echo "1) ".var_export(substr("pear", 0, 2), true).PHP_EOL;
echo "2) ".var_export(substr(54321, 0, 2), true).PHP_EOL;
echo "3) ".var_export(substr(new apple(), 0, 2), true).PHP_EOL;
echo "4) ".var_export(substr(true, 0, 1), true).PHP_EOL;
echo "5) ".var_export(substr(false, 0, 1), true).PHP_EOL;
echo "6) ".var_export(substr("", 0, 1), true).PHP_EOL;
echo "7) ".var_export(substr(1.2e3, 0, 4), true).PHP_EOL;
?>
The above example will output:
1) 'pe'
2) '54'
3) 'gr'
4) '1'
5) false
6) false
7) '1200'
ERRORS /EXCEPTIONS
Returns FALSE on error.
Example #5
<?php
var_dump(substr('a', 1)); // bool(false)
?>
SEE ALSO strrchr(3), substr_replace(3), preg_match(3), trim(3), mb_substr(3), wordwrap(3), String access and modification by character.
PHP Documentation Group SUBSTR(3)