I'm trying to change a single word on a specific line in a file, but I'm having some trouble connecting all together.
Basically, on one line in my file there is a keyword 'firmware_revision', and on this line (and only this line) I want to replace the word 'test' with the word 'production'.
So I can do this:
grep 'firmware_revision' myfile.py | sed 's/test/production'
This will pick out the line I want and perform the substitution, but I can't figure out how to get this new line into the original file to replace the old line. I obviously cannot just redirect it back to the file, so what should I do?
Even if I use temporaries, by using
grep to get just the line I need I lose all of the other data in the file, so I can no longer just redirect it all to a temp file then replace the original with the temp.
Edit - Someone asked for more information
Lets say I have a file full of lines like this
[ ('key_name1', str, 'value1', 'Description'), ('key_name2', str, 'value2', 'Description'), ('key_name3', str, 'value3', 'Description'), ('firmware_revision', str, 'my-firmware-name-test', 'Firmware revision name') ]
now I want to write a script (ideally a one-liner) that will find the line that contains 'firmware_revision', and changes all instances of the word 'test' on that line to 'production'. The word 'test' might be in other places in that file and I do not want those changed. So to be clear, I want to change the above line to
('firmware_revision', str, 'my-firmware-name-production', 'Firmware revision name')
How do I do this?