awk \'/^nameserver/ && !modif { printf(\"nameserver 127.0.0.1\\n\"); modif=1 } {print}\' testfile.txt
It is displaying output but I want to wri
You can also use sponge from moreutils.
sponge
For example
awk '!a[$0]++' file|sponge file
removes duplicate lines and
awk '{$2=10*$2}1' file|sponge file
multiplies the second column by 10.