append out on particular line number

I want to append output of below command to a file name "final" mentioned on line number 9.


sed 's/peter/xyz/g' ttc >> final

you requirement isn't clear. can you give us some example.

awk '{if(NR==9) { print sub("peter","xyz",$0) } else { print $0 }}' ttc 

Lets suppose i have a file final that consist of 15 lines.

I want to append the output of below command on line 9 in above file which have name "final"

sed 's/peter/xyz/g' ttc 

---------- Post updated at 02:52 AM ---------- Previous update was at 02:50 AM ----------

Where is the filename "final", in which i want to append the output at line 9 in final file.

---------- Post updated at 03:04 AM ---------- Previous update was at 02:52 AM ----------

Dear sir,

is it clear to you or not now?

Try this.

awk '{if(NR==9){system("sed 's/abc/ash/g' test.txt")}else {print}}' final.txt 

what about lines after line number 9 ? you want them to printed or not ?

dear sir i dont want to print the line of final.txt, i want that whatever line which we get from sed need to insert under final.txt at line number 9 nothing else.

 
output=`sed 's/peter/xyz/g' ttc`;awk -v out=$output '{ if (NR==9) { print $out} else { print $0}}' final.txt

Fine, did you try the command i have posted , this will work and you need to redirect the output into the new file.