Input:<e1 name=file1 id=id1 anotherId=id2>Desired output:file1I can get what I need with this:echo '<e1 name=file1 id=id1 anotherId=id2>' | sed 's/\(.*name=\)\(.*\)\(.*\)/\2/' | sed 's/.*//'Output: file1I would like to improve the set of commands and remove the last pipe to sed if possible.  If I remove the last pipe to sed, I cannot get what I want:echo '<e1 name=file1 id=id1 anotherId=id2>' | sed 's/\(.*name=\)\(.*\)\(.*\)/\2/'Output:file1 id=id1 anotherId=id2As you can see sed is picking up the last quotation mark and not the first after file1.Can someone help improve this command?
Improve sed command to replace first instance of character and all following characters?
shell script;text processing;sed
echo '<e1 name=file1 id=id1 anotherId=id2>' |  sed -n 's/.*name=\([^]*\).*/\1/p'Or with GNU grep if built with PCRE support:echo '<e1 name=file1 id=id1 anotherId=id2>' |  grep -Po 'name=\K[^]*'