Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text file that is generated by 3rd-party software as part of a build process. I want to replace one specific line - in my case, line 6. How can I do this in my bash script?

I suspect sed is my friend here but I'm now stumped.

I'm using Mac OS X 10.6 if that's important.

share|improve this question
up vote 9 down vote accepted

Try sed "6s/old/new/g" file.txt

share|improve this answer
If you don't care what you're replacing on line six, you can use sed "6s/.*/new/" file.txt too. – Chris S Sep 17 '10 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.