Skip to main content
edited tags
Link
jw013
  • 53k
  • 11
  • 143
  • 142
Source Link
robintw
  • 263
  • 3
  • 7

Replace whole line in a file from command-line

I have a text file which has some contents similar to this:

# General information about the project. project = u'Py6S' copyright = u'2012, Robin Wilson' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '0.5' # The full version, including alpha/beta/rc tags. release = '0.5' 

I would like to replace the version = '0.5' line with version = X where X is a command-line argument given to a script, and then do the same for the release = line.

Is there a simple command I can call to do this sort of replacing? I've looked into sed a bit, but it seems that the global substitution in sed would require me to search for version = '0.5', but all I really want to search for is a line beginning with version = - as I have no idea what the version might be when I run the script!

Any ideas?