I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear...I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck:sed -i.bak s/*.ear/ear2.ear/g earlist.mpswhere earlist.mps is the file nameI have tried:sed -i.bak s/.*.ear/ear2.ear/g earlist.mpsbut this replaces the whole file with ear2.ear.
How can I replace a filename with .ear in a file-list using sed?
shell script;sed;scripting;search;replace
With sed:sed 's|/[^/]\+\.ear$|/ear2.ear|' fileIt seaches for line ending with .ear ($ matches the end of the line). The filename can be everything except a /: [^/]\+. The + indicates that a character (which is not a /) can be repreated 1 or more times.Then is replaces that match with /ear2.ear.