I have a file r. I want to replace the words File and MINvac.pdb in it with nothing. The commands I used are
sed -i 's/File//g' /home/kanika/standard_minimizer_prosee/r
and
sed -i 's/MINvac.pdb//g' /home/kanika/standard_minimizer_prosee/r
I want to combine both sed commands into one, but I don’t know the way. Can anyone help?
The file looks like this:
-6174.27 File10MINvac.pdb
-514.451 File11MINvac.pdb
4065.68 File12MINvac.pdb
-4708.64 File13MINvac.pdb
6674.54 File14MINvac.pdb
8563.58 File15MINvac.pdb
sedis a scripting language. You separate commands with semicolon or newline. Manyseddialects also allow you to pass each command as a separate-eoption argument.I also added a backslash to properly quote the literal dot before
pdb, but in this limited context that is probably unimportant.For completeness, here is the newline variant. Many newcomers are baffled that the shell allows literal newlines in quoted strings, but it can be convenient.
Of course, in this limited case, you could also combine everything into one regex:
(Some
seddialects will want this without backslashes, and/or offer an option to use extended regular expressions, where they should be omitted. BSDsed, and thus also MacOSsed, demands a mandatory argument tosed -iwhich can however be empty, likesed -i ''.)