Hi, Iam new to unix. I have one input file .
Input file :
ID1~Name1~Place1
ID2~Name2~Place2
ID3~Name3~Place3
I need output such that only first column should change to fixed width column of 15 characters of length.
Output File:
ID1<<12 spaces>>Name1~Place1
ID2<<12... (5 Replies)
Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2
file 1 sample
SNDK 80004C101 AT
XLNX 983919101 BB
NETL 64118B100 BS
AMD 007903107 CC
KLAC 482480100 DC
TER 880770102 KATS
ATHR 04743P108 KATS... (7 Replies)
Hi everyone, and thanks after all
I'm a biologist and i have to extract information from one text. The text is something like this
1023 A A 56 0 cc...,,,,..gg..Cc.c,,c..CC..,,
1024 T T 86 0 ..,,,..aaAA..,,aAA,,a,,A,,a
1025 G G 125 0 ... (5 Replies)
Hi
I wanted to fetch particular characters from a column.I have a file having columns separated by pipe operator.
The contents of the file are Task | Task started on a component | B678C56D-96DA-4FFC-B40E-9A032A2EB12E-0000004 | service.adapter:UCF Version Creator
... (2 Replies)
Hello all,
I have a data like this:
X:04252 X:05524 X:04176
X:05509 X:05524 X:04674-
X:1662912 X:10181
X:16491 X:05506
X:05216- X:05488
X:46872 X:08471
X:04834 X:30170
The except result is like this:
X:04252 X:05524 X:04176
X:05509 X:05524 X:04674
X:16629 X:10181... (3 Replies)
This is my input file :
# cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9
This is the required output
... (1 Reply)
I need to delete the last 11 characters from each number and they are all in the same line (each is in a different column):
-6.89080901827020800000 3.49348891708562325136 1.47988367839905286876 -2.29707635413510400000 -3.49342364708562325136 -4.43758473239905286876 -2.29707635413510400000... (14 Replies)
I have a file as follows
ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N
ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C
ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C
ATOM 5184 O MET K... (14 Replies)
Hi,
My input files is like this
axis1 0 1 10
axis2 0 1 5
axis1 1 2 -4
axis2 2 3 -3
axis1 3 4 5
axis2 3 4 -1
axis1 4 5 -6
axis2 4 5 1
Now, these are my following tasks
1. Print a first column for every two rows that has the same value followed by a string.
2. Match on the... (3 Replies)
Hello all,
I want to consolidate my data group by cities into 4 rolled up code categories (first 2 characters of 2nd col), namely PR, GR, TY and others.
CHICAGO PR1
CHICAGO GR3
CHICAGO GR4
CHICAGO HT5
CHICAGO HT6
CHICAGO TY5
HOUSTON PR3
HOUSTON PR9
HOUSTON TY4
HOUSTON HJ5... (1 Reply)
Discussion started by: jalaj841
1 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)