09-17-2009
Guys...i ve got a logic here..
A.txt
-----
AAA
BBB
B.txt
-----
CCC
AAA
BBB
DDD
script
------
cat A.txt | while read var1
do
echo $var1
grep $var1 B.txt | sed -n -e '1p' >> tmp
done
diff -w A.txt tmp
Now i want to print Pass/Fail based on the output from diff...how can i do it ?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello,
I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3.
For example:
file 1
123
1234
123456
file 2
123
2345
23456
file 3 should have
2345
23456
I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
2. UNIX for Dummies Questions & Answers
I have file1 and file2. I am trying to get the difference between the two of them to another file? I have tried diff and fgrep with no luck.. I dont think I am using the proper switches to make this happen.
Can someone please give me the key to this lock?
Muchos Thanks.
Tbone (2 Replies)
Discussion started by: jtrevinojr
2 Replies
3. Shell Programming and Scripting
I need to compare 2 diff type of files and find out the duplicate after comparing each types of files:
Type 1 file name is like: file1.abc
(the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations).
The other file is file1.bcd01abc (the extension... (2 Replies)
Discussion started by: ricky007
2 Replies
4. Shell Programming and Scripting
Hi Masters,
I have two files named file1 and file2.
Both the files contains the same contents with some difference in comments,space.But no content change.
I tried to find the diff between the two files to make sure that contents are same.
For that i tried
diff -ibw file1 file2
But... (1 Reply)
Discussion started by: ecearund
1 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I use the diff command to compare two files and append this output to a file. I would like to now not only produce the differences but be able to output the total number of changes made, the number of new files added and the number of files deleted, is there I can do this using the diff... (2 Replies)
Discussion started by: cyberfrog
2 Replies
6. Shell Programming and Scripting
Hi All,
I have two files which look as below
File1
serial="1" name="abc" type="employee" field="IT"
serial="2" name="cde" type="intern" field="Marketing"
serial="3" name="pqr" type="contractor" field="IT"
serial="4" name="xyz" type="employee" field="Sales"
File2
serial="1"... (3 Replies)
Discussion started by: grajp002
3 Replies
7. Shell Programming and Scripting
Hi
I've been trying various methods that I have found online with regards to comparing 2 files using the diff command. Nothing seems to work. The problem is that I'm not too familiar with the proper syntax. Can you please assist me. Here is my script:
#!/bin/bash
awk -F',' -v file1="$1"... (9 Replies)
Discussion started by: ladyAnne
9 Replies
8. Shell Programming and Scripting
Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies
9. Shell Programming and Scripting
Hi,
I need a small help to compare two PIPE delimited files.
Note : All The Files Have A Column Name
Example:
file1.txt
=================
column1|column2|column3
one|two|three
four|five|six
seven|eight|nine
file2.txt
=================
column1|column2|column3
1|two|three... (2 Replies)
Discussion started by: anshultongia
2 Replies
10. Shell Programming and Scripting
Guys i have 3 files,
but i want to compare and diff only the 2nd column
path=`/home/whois/doms`
for i in `cat domain.tx`
do
whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant
whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 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)