Duplicate value

Hi All,

i have file like

 ID|Indiv_ID
12345|10001
     |10001
     |10001
23456|10002
     |10002
     |10002
     |10002
     |10003
     |10004

if indiv_id having duplicate values and corresponding ID column is null then copy the id.
I need output like:

ID|Indiv_ID
12345|10001
12345|10001
12345|10001
23456|10002
23456|10002
23456|10002
23456|10002
     |10003
     |10004

Thanks

What have you tried so far?

Not able get any idea how to check the duplicate records...Please help me...

awk -F\| 'BEGIN{OFS=FS} 
FNR>1 {if(++a[$2]>1 && $1 ~ /^ *$/) $1=lastID;if($1 !~ /^ *$/)lastID=$1}1' inputfile
awk -F"|" '{a[$2]=a[$2]?a[$2]:$1; $1=a[$2]}1' OFS="|" file

Thanks.... in this case it is not working...
input file...

ID|Indiv_ID
12345|10001
12347|10001
     |10001
23456|10002
     |10002
     |10002
     |10002
     |10001
     |10003
     |10004

Output coming as

ID|Indiv_ID
12345|10001
12347|10001
12347|10001
23456|10002
23456|10002
23456|10002
23456|10002
23456|10001
     |10003
     |10004

But this records: 23456|10001 should not come like..

Excepted output is

12345|10001
12347|10001
12347|10001
23456|10002
23456|10002
23456|10002
23456|10002
12347|10001
     |10003
     |10004 

Thanks...

awk -F\| 'BEGIN {OFS=FS} FNR>1 {
 if(++cnt[$2] > 1 && $1 ~ /^ *$/)
  $1=last[$2]
 if($1 !~ /^ *$/)
  last[$2]=$1
}
1' inputfile

you are ROCK...Great

Try...

$ cat file1
ID|Indiv_ID
12345|10001
12347|10001
     |10001
23456|10002
     |10002
     |10002
     |10002
     |10001
     |10003
     |10004

$ awk 'BEGIN{FS=OFS="|"}{if($1~/^ *$/){if(a[$2]){$1=a[$2]}}else{a[$2]=$1};print}' file1
ID|Indiv_ID
12345|10001
12347|10001
12347|10001
23456|10002
23456|10002
23456|10002
23456|10002
12347|10001
     |10003
     |10004

$

Thanks lot all....
output not coming properlly...this record " |10002" should come as 23456|10002.

ID|Indiv_ID
12345|10001
12347|10001
     |10002
23456|10002
23456|10002
23456|10002
23456|10002
12347|10001
     |10003
     |10004

---------- Post updated at 09:30 AM ---------- Previous update was at 09:28 AM ----------

if you give the input as below

ID|Indiv_ID
12345|10001
12347|10001
     |10002
23456|10002
     |10002
     |10002
     |10002
     |10001
     |10003
     |10004

output put coming as above.....

---------- Post updated at 11:42 AM ---------- Previous update was at 09:30 AM ----------

Please help me how to achive this one...

You need to do a better job of explaining your requirements...and instead of coming back repeatedly with questions try to extend the solutions presented so you get better at programming. So you have 2 columns and they both could be missing values so what is the criteria to be used for filling up those missing values...be as clear as possible and explain with sample input and output.

It's not allowed to bumping up posts, please read the rules.

I tried the solutions above and they give me both the desired output.