Thursday, December 8, 2011

Displaying only matching regex with sed

sed -n 's/stuff\(.*\)more stuff/\1/p'

This will only show the data matched by the parenthesised expression.

The following example shows only unique filenames leaving out paths:
find . -iname "*file*"| sed  -n 's/.*\/\(.*\)$/\1/p' | sort | uniq | less