0

Lets say I did this:

 echo stackoverflow > file
 grep sta[a-z]*w file

grep result is stackoverflow

But how do I get only original pattern sta & w?

4

2 回答 2

2
grep -oE 'sta|w'

或者

grep -o 'sta\|w'

应该给你想要的。例如:

kent$   echo "stakoverflow"|grep -oE 'sta|w'
sta
w
于 2013-04-30T15:22:24.340 回答
1

如果您打算概括staw,那么此版本可能会有所帮助:

echo stackoverflow > file
grep 'sta[a-z]*w' file | sed 's/\(sta\)[a-z]*\(w\)/\1 \2/'
于 2013-04-30T15:38:57.210 回答