I'd like to replace one string from one file with a string from another file. Though I'm not experienced with these commands, I expect some combination of grep and sed would do it best.
What makes this a bit more complicated is that I don't know what either string is (I'm trying to automate replacing the version number on my documentation). I do know that in both cases the string I'm looking for (say "2.3.4") is preceded by "version:"
So can I say 'look for word (or rest of line or whatever is possible) after "version:" (let's call it string1) and do the same in another file (giving string2) and replace string string1 with string2.
Here are some example text files:
file1.txt
This is a file containing
the updated version number.
version: 2.3.4
here is a string with more info
file2.txt
This is a configuration file
It could contain an old version number
version: 2.3.2
Please update this
So the expected output for file2.txt would become:
file2.txt
This is a configuration file
It could contain an old version number
version: 2.3.4
Please update this
Thanks
See Question&Answers more detail:os