mryqu> cat test.txt
Hello from="Beijing" via="Nanjing" to="Shanghai".
test
123
mryqu> sed -e 's/^Hello.*from="[^"]\+".*$/abc/g' test.txt
abc
test
123
mryqu> sed -e 's/^Hello.*from="\([^"]\+\)".*$/\1/g' test.txt
Beijing
test
123
mryqu> sed -e 's/^\(Hello.*from="\)\([^"]\+\)\(".*\)$/\1********\3/g' test.txt
Hello from="********" via="Nanjing" to="Shanghai".
test
123
mryqu> sed -e 's/^\(Hello.*from="\)\([^"]\+\)\(".*\)$/\1********\3/g' -e 's/^\(Hello.*to="\)\([^"]\+\)\(".*\)$/\1********\3/g' test.txt
Hello from="********" via="Nanjing" to="********".
test
123
mryqu>
注:sed不支持非贪婪模式。