How can I replace a string but only in the first line of the file using the program \"sed\"?
The commands s/test/blah/1 and 1s/test/blah/ d
s/test/blah/1
1s/test/blah/
This might work for you (GNU sed):
sed -i '1!b;s/test/blah/' file
will only substitute the first test for blah on the first line only.
test
blah
Or if you just want to change the first line:
sed -i '1c\replacement' file