Possible Duplicate:
Extracting a regex matched with 'sed' without printing the surrounding characters
How do I make this only print test:
echo "atestb" | sed -n 's/\(test\)/\1/p'
How do I make this only print
|
|||
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
sed?grep's-oswitch looks like a shorter and cleaner way:echo "atestb" | grep -o 'test'. – manatwork Jul 16 '12 at 7:54echo 'afoo="test"b' | sed -n 's/.*foo="\([^"]*\)".*/\1/p', where I only want to matchtest. – Tyilo Jul 16 '12 at 15:53