I have a text file and i want to replace a word from a specific location. For example want to replace 5th word from 12th line of file. How i can do that?

Read the file one word at a time, saving the words in another file except replace the 5th word (or whatever number it is) with the new word. You need two files, an input file and an output file.

Once you have read the target word and written the replacement into the output file, you can read/write the rest of the source file into the output file, in chunks, for efficiency's sake.