Initially I had a mistake in my below, so I'm editing and reopening this.
I'm having some problems injecting lines into files. My goals are:
- Look for the line (in this case
VIMLINE
). If the line is there, do nothing (or remove the line, I have need to do both 'do nothing' and 'remove the line' at different times, but don't know how to fit removal in - removal is for situations where I want to ensure that I am injecting at the end of the script). - If the line is not there (which is what
||
should do, I thought) then append the line to the end of the script.
The following works perfectly for injecting a line that is not already in a file into that file.
VIMLINE='color industry'
grep -qxF "$VIMLINE" ~/.vimrc || echo $VIMLINE | sudo tee --append ~/.vimrc
My question then is, how could I modify the above to: look for a line (or part of a line) and remove that line and then reinject that line (so as to guarantee that the line is added to the end of the file)?