In Reference to this question After getting the line identifier matching in first and second file I need to replace the line in first file with the line of second file.For that
You can't replace one line with another in place. Because lines usually has different length and will overlap each other. If all lines in your file are the same length then it can work. I also suggest you use more suitable language for this task (like Perl for example) because it will be really complicated code in Shell. I think that you should look for a solution with temporal files, because it'll easier to implement and it can be debugged easily. Just imagine what will you do if your huge file will be currupted due to the bug in the script.