Replace the perticular fileds in passwd file

Hi I have 2 different password entries in 2 different files for the same user.

file 1 -

siva:correct:1000:23:siva:/home/siva:/bin/bash

file 2 -

siva:incorrect:1000:23:siva:/home/siva:/bin/bash

file 1 is having correct passwd entry where as file 2 is wrong.

Now, i want to compare both lines and change passwd entry from file 1 to file 2

Finally file1 and file 2 should be the same ..

siva:correct:1000:23:siva:/home/siva:/bin/bash

Please suggest.

Hello kumar85shiv,

Please use CODE TAGS as per forum rules for commands/codes/Input_file samples which you are using into your post.
Could you please try following and let me know if this helps you.

awk -F":" 'FNR==NR{a[$1]=$0;next} ($1 in a) && $2=="incorrect"{print a[$1];next} 1'  Input_file1   Input_file2

Above command will show output for only correcting Input_file2, if you are happy with above command's output then you could use following command to have output saved into Input_file2 itself.

awk -F":" 'FNR==NR{a[$1]=$0;next} ($1 in a) && $2=="incorrect"{print a[$1];next} 1'  Input_file1   Input_file2 > temp_file && mv temp_file  Input_file2

Thanks,
R. Singh

Thank you Ravindra, It works fine here

It's highly dangerous to mess around with system files (e.g. password files) NOT using the tools designed for it. You might end up not being able to access the system.

For the sheer exercise: How is the user identified - by user name (field 1), UID (field 3), or both? And, it's just about field 2, so all the other fields in file 2 will stay the same? Assuming both, why don't you copy the entire line?
Try

awk -F: 'NR==FNR {T[$1,$3] = $0; next} $1,$3 in T {$0 = T[$1,$3]} 1' file1 file2