Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Lets say I did this:
echo stackoverflow > file grep sta[a-z]*w file
grep result is stackoverflow
stackoverflow
But how do I get only original pattern sta & w?
sta
w
grep -oE 'sta|w'
或者
grep -o 'sta\|w'
应该给你想要的。例如:
kent$ echo "stakoverflow"|grep -oE 'sta|w' sta w
如果您打算概括sta和w,那么此版本可能会有所帮助:
echo stackoverflow > file grep 'sta[a-z]*w' file | sed 's/\(sta\)[a-z]*\(w\)/\1 \2/'