How to Remove duplicate value from file?

if different branch code is available for same BIC code and one of the branch code is XXX.only one row will be stored and with branch code as XXX .rest of the rows for the BIC code will not be stored.

for example if $7 is BIC code and $8 is branch code
INPUT file are following

BI	M	IT056868	UNICREDI	VIA	LIBHIA	UNCRIT2B	XXX	UNCR
BI	M	US001165	NEUBERGE	LLC	NEWYRK	NEUBUS33	253	NEUB
HH	M	IND90909	SBILIFES	HNI	NANANN	GGGGGGGG	142	UICC
HH	M	MNOOOO	        98989089	IIC	UMNKSS	MOHAN844	XXX	KLKL
HH	M	MNKKKKKK	90909090	JMV	MNJKMN	MOHAN844	256	LOPD
HH	M	MKLJHJKK	KIKIKIKI	JKJ	NMHMNM	MOHAN844	456	LOPS

here $7 is having 3 bic code with same value"MOHAN844" with diff branch code in $8 and i want only BIC code with XXX value ...and if XXX is not present in $8 then i need all record..

please Help me..

I think this is more correct

awk '{if ($8=="XXX") {arr[$7]=$0} else if (!arr[$7]) {arr[$7]=$0}} END {for (i in arr) print arr}' infile
BI      M       IT056868        UNICREDI        VIA     LIBHIA  UNCRIT2B        XXX     UNCR
HH      M       MNOOOO          98989089        IIC     UMNKSS  MOHAN844        XXX     KLKL
BI      M       US001165        NEUBERGE        LLC     NEWYRK  NEUBUS33        253     NEUB
HH      M       IND90909        SBILIFES        HNI     NANANN  GGGGGGGG        142     UICC

get every single instance of $7 , but keep the one line that have XXX in $8

---------- Post updated at 13:09 ---------- Previous update was at 12:49 ----------

Some updated.

awk '$8=="XXX" {arr[$7]=$0} !arr[$7] {arr[$7]=$0} END {for (i in arr) print arr}' infile

Thank you very much for your quick reply ..
but for this input ..

BI    M    IT056868    UNICREDI    VIA    LIBHIA    UNCRIT2B    XXX    UNCR
BI    M    US001165    NEUBERGE    LLC    NEWYRK    NEUBUS33    XXX    NEUB
HH    M    IND90909    SBILIFES    HNI    NANANN    GGGGGGGG        UICC
HH    M    MNOOOOO    98989089    IIC    UMNKSS    MOHAN844    XXX    KLKL
HH    M    MNKKKKKK    90909090    JMV    MNJKMN    MOHAN844    256    LOPD
HH    M    MKLJHJKK    KIKIKIKI    JKJ    NMHlMM    MOHAN844    456    LOPS
HH    M    IND90909    SBILIFES    HNI    NANAAN    MSSMSSM    123    UIHH
HH    M    IND90909    SBILIFES    HNI    NAANAN    MSSSMSM    234    UIHH
HH    M    IND90909    SBILIFES    HNI    NANANAN    MSSSMSM    543    UIHH

but last three row is not printing...
condition is given is if among all the branch code ($8) for same BIC code($7) "XXX" is not present then i have to print as usual...duplicate value only remove when XXX is present in among all the Branch code for same Bic code...

Use CODE TAGS
I get this output, seems for me correct:

BI      M       IT056868        UNICREDI        VIA     LIBHIA  UNCRIT2B        XXX     UNCR
HH      M       MNOOOOO         98989089        IIC     UMNKSS  MOHAN844        XXX     KLKL
HH      M       IND90909        SBILIFES        HNI     NAANAN  MSSSMSM         234     UIHH
HH      M       IND90909        SBILIFES        HNI     NANAAN  MSSMSSM         123     UIHH
BI      M       US001165        NEUBERGE        LLC     NEWYRK  NEUBUS33        XXX     NEUB
HH      M       IND90909        SBILIFES        HNI     NANANN  GGGGGGGG        UICC

Edit
Ok, if I understand you correctly.
If $8 do contain XXX , keep only the line with XXX .
If $8 does not have XXX , keep all line with same $7 .
This will make it much more complicated since all can not fit into one simeple array

PS, always give output example.
PS, you miss one coloumn in row 3
PS, you have a possible type MSS MS etc

This will sort your Branch codes alphabetically - not sure if you'd care about that...

crabshack:foo toki$ cat foo.txt
BI M IT056868 UNICREDI VIA LIBHIA UNCRIT2B XXX UNCR
BI M US001165 NEUBERGE LLC NEWYRK NEUBUS33 XXX NEUB
HH M IND90909 SBILIFES HNI NANANN GGGGGGGG UICC
HH M MNOOOOO 98989089 IIC UMNKSS MOHAN844 XXX KLKL
HH M MNKKKKKK 90909090 JMV MNJKMN MOHAN844 256 LOPD
HH M MKLJHJKK KIKIKIKI JKJ NMHlMM MOHAN844 456 LOPS
HH M IND90909 SBILIFES HNI NANAAN MSSMSSM 123 UIHH
HH M IND90909 SBILIFES HNI NAANAN MSSSMSM 234 UIHH
HH M IND90909 SBILIFES HNI NANANAN MSSSMSM 543 UIHH
crabshack:foo toki$ cat foo.sh
#!/bin/bash

file=foo.txt
unique_branch=$( awk '{print $7}' ${file} | sort | uniq )

for branch in ${unique_branch}; do
	grep_output=$( grep " ${branch} XXX " ${file} )
	if [ "$?" -eq "0" ]; then
		echo "${grep_output}"
	else
		grep " ${branch} " ${file}
	fi
done

exit 0
crabshack:foo toki$ ./foo.sh
HH M IND90909 SBILIFES HNI NANANN GGGGGGGG UICC
HH M MNOOOOO 98989089 IIC UMNKSS MOHAN844 XXX KLKL
HH M IND90909 SBILIFES HNI NANAAN MSSMSSM 123 UIHH
HH M IND90909 SBILIFES HNI NAANAN MSSSMSM 234 UIHH
HH M IND90909 SBILIFES HNI NANANAN MSSSMSM 543 UIHH
BI M US001165 NEUBERGE LLC NEWYRK NEUBUS33 XXX NEUB
BI M IT056868 UNICREDI VIA LIBHIA UNCRIT2B XXX UNCR

but i want to keep all the record of same BIC code with duplicate branch code if XXX is not present among all the branch code of same BIC code..

---------- Post updated at 06:30 PM ---------- Previous update was at 06:10 PM ----------

Thanks zazzybob
but , if i am executing this query its running but output is not coming on the screen ..can u provide me in details or can u give me a query with output should store in file.

As long as you specify the correct path to your input file in the file variable in the script, it should work. In the example below the input file is foo.txt and it exists in the same directory as foo.sh , which is also your present working directory.

i have checked everything ....file ar also reading but output is no showing please can u give query for writing output in file......because this is the output what i need .....so please

Just redirect the output to a file.

$ ./foo.sh > foo.output

Not sure what you mean by "file ar also reading but output is no showing". The script generates output for me.

Hi zazzybob,
if input file is like following then..

BI	M	IT056868	UNICREDI	VIA	LIBHIA	UNCRIT2B	XXX	UNCR	UNCRIT2B	XXX	UNCR
BI	M	US001165	NEUBERGE	LLC	NEWYRK	NEUBUS33	XXX	NEUB
HH	M	IND90909	SBILIFES	HNI	NANANN	GGGGGGGG		UICC
HH	M	MNOOOOwO	98989089	IIC	UMNKSS	MOHAN844	XXX	KLKL	MOHAN844	XXX
HH	M	IND90909	SBILIFES	HNI	NANAAN	MSSSMSSM	123	UIHH	MSSSMSSM	123
HH	M	IND90909	SBILIFES	HNI	NAANAN	MSSSMSSM	234	UIHH
HH	M	IND90909	SBILIFES	HNI	NANANA	MSSSMSSM	543	UIHH
BI	M	ES063710	CAJAMEDI	TER	RANEOR	BCOEESMM	821	BCOEESMM	XXX	BCOE	ES	
BI	M	ES063711	CAJARURA	DEL	MEDITE	BCOEESMM	821	BCOEESMM	XXX	BCOE	ES	
BI	M	ES063777	CAJARURA	DEL MEDITE	BCOEESMM	821	BCOEESMM	XXX			BC
BI	M	ES063838	CAJARURA	DEL MEDITE	BCOEESMM	821	BCOEESMM	XXX			BC
BI	M	ES063838	CAJARURA	DEL MEDITE	BCOEESMM	XXX	BCOEESMM	XXX			BC

and i want same output what i explained above...and if $7 value is duplicate and $8 value is also XXX of both value of $7.then i want only one row no other duplicate value..