Diff command with a condition

Hi

I have 2 files test1 & test2.

Test1 contains :
BSC
AFCN

Test2 contains:
AFCN

I than use the following command :

diff file1 file2

which displays than displays : 2d1
< BSC

Basically I want to confirm that except for "BSC", AFCN is the only word in each file.So when I do a "Diff" how do i say do not take "BSC" into consideration but just check for other differences(in this case only AFCN)?

Thanks & Regards
Pragesan

Well the most obvious would be to remove the unwanted line before to use diff...
To really help you, we would need to know a bit more:
Is this case always true? (First line unwanted) etc...

Hi vbe

Thanks for the reply.

Yes this is always true.File1 i.e Test1 will always contain the first line "BSC" which I don't want.So when i'm doing the diff between the two files I'm hoping to see only 1 difference i.e the word "BSC" but to make it easier for others to read I would like the diff command not to take the first line of Test1 into consideration. and thus have no differences.

I hope this makes sense

Thanks & Regards
Pragesan

if you want to compare test1 and test2 but ignore ALL "BSC" from test1:

grep -v 'BSC' test1|diff - test2

if you want to compare test1 and test2 but ignore the 1st line from test1:

sed -n '2,$p' test1|diff - test2

Hi sk1418

Thanks for your reply.Both of your commands work.I need the second command :slight_smile:

I'm extremly new to unix.Please could you explain command 2.It will help me a lot going forward.

sed -n '2,$p' test1|diff - test2
Thank you once again.
.

sed command will cut the 1st line from your test1 file, and pass the result to diff command via pipe, to compare with test2 file.

Since your new at unix, you could have a look at the man pages of tail and head commands, for you could have used e.g.

 tail -n +2 test1

maybe more accessible for a novice than having to assimilate sed (and awk) syntax, nevertheless you would have to use it in the same way as the bright example of sk1418 since diff wants 2 files in input you have to use "-" to say "Standard Input - to be used as file1"...