Thank you for your prompt reply
and it helps me to proceed further. But still I am missing some thing.
Output of the command " sed "s%$(head -1 file1.txt)%#\!$(which ruby)%g" file1.txt " is displaying the modified shebang line along with the contents of the file on the console. But if I pass the o/p using tee operator to the same file the whole contents of the file has been lost.
command:
sed "s%$(head -1 file1.txt)%#\!$(which ruby)%g" file1.txt | tee file1.txt
So I have found a work around to pass the o/p of the command "sed "s%$(head -1 file1.txt)%#\!$(which ruby)%g" file1.txt" to a temparary file and then copying the contents of the temparary file to the original.
command:
sed "s%$(head -1 file1.txt)%#\!$(which ruby)%g" file1.txt | tee file2.txt
cp file2.txt file1.txt
Is there any way I can accomplish the whole task from a single sed command?