06-18-2010
No I meant more like if I have a string like fat#bob
I get...
Using one AWK script would return the last name, in this case fat.
Another AWK script would return the first name, in this case bob.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
Can you please help me?
How to Parse a comma delimited and optionally quotes dimilited file?
sample.dat
----------
"I",+2007,"SANDA, 20, MARTIN PLACE","SANDA 20MARTIN"
"D",+2008,"RANDA, 22, MARTIN PLACE","RANDA 22MARTIN"
Thank you.
Ram (8 Replies)
Discussion started by: vramana2003
8 Replies
2. Shell Programming and Scripting
When parsing multiple fields in a file using AWK, how do you group by one of the fields and parse by delimiters?
to clarify
If a file had
tom | 223-2222-4444 , randofield
ivan | 123-2422-4444 , random filed
... | and , are the delimiters ...
How would you group by the social security... (4 Replies)
Discussion started by: Josef_Stalin
4 Replies
3. Shell Programming and Scripting
Hi
I am trying to figure out the best way to search a long log file and print out certain information.
For example if I had a line in a log file delimited by ampersand
first_name=mike&last_name=smith&zip_code=55555&phone=555-5555&state=ma&city=boston
and I only wanted to search for and... (3 Replies)
Discussion started by: mstefaniak
3 Replies
4. Shell Programming and Scripting
I am fairly new to programming and trying to resolve this problem. I have the file like this.
CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam
tg93 77 T C T T T T T
tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies
5. UNIX for Advanced & Expert Users
Hi experts,
e.g.
i/p data looks like
0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747,9700005405717924,9700005405733788|unidentified,unidentified,unidentified||
o/p data should like -
row1: 0000xm7zcNDIkP888vRqGv93xA7:176n00qql||9700005405552747|unidentified
... (1 Reply)
Discussion started by: sumoka
1 Replies
6. Shell Programming and Scripting
Hi Experts,
I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output
file:
###############################################################################################
PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies
7. Shell Programming and Scripting
Hello:
I am working parsing a large input file which will be broken down into multiples based on the second field in the file, in this case: STORE.
The idea is to create each file with the corresponding store number, for example: Report_$STORENUM_$DATETIMESTAMP , and obtaining the... (7 Replies)
Discussion started by: ec012
7 Replies
8. Shell Programming and Scripting
I am trying to parse the input in awk to include the |gc= in $4 but am not able to. The below is close:
awk so far:
awk '{sub(/\|]+]++/, ""); print }' input.txt Input
chr1 955543 955763 AGRN-6|pr=2|gc=75 0 +
chr1 957571 957852 AGRN-7|pr=3|gc=61.2 0 +
chr1 970621 ... (7 Replies)
Discussion started by: cmccabe
7 Replies
9. UNIX for Beginners Questions & Answers
Hi there,
I would like to use awk to reformat a tab-delimited file containing three columns as follows:
Data file:
sample 1 173
sample 269 530
sample 687 733
sample 1699 1779
Desired output file:
sample 174..265, 531..686, 734..1698
I need the value... (5 Replies)
Discussion started by: emiley
5 Replies
10. Shell Programming and Scripting
Hi Experts,
Please support
I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6.
... (3 Replies)
Discussion started by: as7951
3 Replies
LEARN ABOUT PHP
substr_replace
SUBSTR_REPLACE(3) 1 SUBSTR_REPLACE(3)
substr_replace - Replace text within a portion of a string
SYNOPSIS
mixed substr_replace (mixed $string, mixed $replacement, mixed $start, [mixed $length])
DESCRIPTION
substr_replace(3) replaces a copy of $string delimited by the $start and (optionally) $length parameters with the string given in $replace-
ment.
PARAMETERS
o $string
- The input string. An array of strings can be provided, in which case the replacements will occur on each string in turn. In
this case, the $replacement, $start and $length parameters may be provided either as scalar values to be applied to each input
string in turn, or as arrays, in which case the corresponding array element will be used for each input string.
o $replacement
- The replacement string.
o $start
- If $start is positive, the replacing will begin at the $start'th offset into $string. If $start is negative, the replacing will
begin at the $start'th character from the end of $string.
o $length
- If given and is positive, it represents the length of the portion of $string which is to be replaced. If it is negative, it rep-
resents the number of characters from the end of $string at which to stop replacing. If it is not given, then it will default to
strlen( $string ); i.e. end the replacing at the end of $string. Of course, if $length is zero then this function will have the
effect of inserting $replacement into $string at the given $start offset.
RETURN VALUES
The result string is returned. If $string is an array then array is returned.
EXAMPLES
Example #1
Simple substr_replace(3) examples
<?php
$var = 'ABCDEFGH:/MNRPQR/';
echo "Original: $var<hr />
";
/* These two examples replace all of $var with 'bob'. */
echo substr_replace($var, 'bob', 0) . "<br />
";
echo substr_replace($var, 'bob', 0, strlen($var)) . "<br />
";
/* Insert 'bob' right at the beginning of $var. */
echo substr_replace($var, 'bob', 0, 0) . "<br />
";
/* These next two replace 'MNRPQR' in $var with 'bob'. */
echo substr_replace($var, 'bob', 10, -1) . "<br />
";
echo substr_replace($var, 'bob', -7, -1) . "<br />
";
/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', 10, -1) . "<br />
";
?>
Example #2
Using substr_replace(3) to replace multiple strings at once
<?php
$input = array('A: XXX', 'B: XXX', 'C: XXX');
// A simple case: replace XXX in each string with YYY.
echo implode('; ', substr_replace($input, 'YYY', 3, 3))."
";
// A more complicated case where each replacement is different.
$replace = array('AAA', 'BBB', 'CCC');
echo implode('; ', substr_replace($input, $replace, 3, 3))."
";
// Replace a different number of characters each time.
$length = array(1, 2, 3);
echo implode('; ', substr_replace($input, $replace, 3, $length))."
";
?>
The above example will output:
A: YYY; B: YYY; C: YYY
A: AAA; B: BBB; C: CCC
A: AAAXX; B: BBBX; C: CCC
NOTES
Note
This function is binary-safe.
SEE ALSO
str_replace(3), substr(3), String access and modification by character.
PHP Documentation Group SUBSTR_REPLACE(3)