Thank you for all your contributions. Both solutions reproduced file1 again. There is a little difference in what I want. The differences are in the values after DefaultDepth (which is "DefaultDepth 24" in file1, but I want it to be different eg in this case "DefaultDepth 16") and Modes (which is Modes "1024x768" "800x600" "1024x768" in file1 but I want it to be like Modes "640x480" "800x600" "1024x768", notice the differences in the first fields)
The file1 also contents other "Section" such as Section "Device" ---- Ensection, Section "Locale" ......, Ensection, etc so I don't want to overwrite it.
I just want to repalce all contents between "Section "Screen"" and "Ensection" in the file1 with all contents of file2 (I generated file2 from some configurations using "sed" and "awk" commands) and the result should replace values between Section "Screen" and Ensection.
Thanks. It did the job partly. It repeated the lines and I got 504 lines in file1. It inserted the correct lines, but the Endsection appeared somehere in between, it should be the last line.
I have succeeded in getting the output I want, but as I said I do not want to overwrite file1 as it has other Section/Endsection eg Section "Device" ...... Endsection, Section "Mouse" ...... Endsection, etc. I know I can copy file to say file1.temp and manipulate file1.temp to obtaine waht I want for Section "Screen" ..... Endsection the overite it (file1.temp), but after this I need to replace the portion where Section "Screen" .... Endsection appears in file1 with the whole contents of file1.temp.
Is there a way to repalce a portion (section) of a file with the contents of another file?
Can you please check my last code..i have edited the same to match your requirements..Apologies for last code not working for you and so again if it doesn't...