In file my_file.ini
, I want to modify the line starting with dataspecs
like so:
replace dataspecs old_val old stuff blah blah ! blah blah
with
dataspecs $new_val ! blah blah
, where new_val
is a bash variable, and everything after the !
is preserved. Also, I don't know the value of old_val
.
I don't care whether it's sed
or awk
or just bash, I'm just looking for a simple answer that I can understand. I would really appreciate a solution, especially if you could explain what the code of the solution means, for someone who is just learning sed and awk (not the easiest code to look at). Thanks!
Use sed:
PS: I am using inline flag
-i
of sed for inline editing, this will save the modified file.I'd suggest this form of sed:
Add
-i
option if you want to modify the file directly.