Tuesday, July 15, 2014

How to list files that match one but not other pattern

If you want to list files that match one pattern but not other pipe grep command twice.
For example to list files that are .bed files but that do not contain phrase 'peaks' in them use:

ls | grep ".bed" | grep -v "peaks"

Or to list files that are .bed files that do contain this phrase in the name of the file:

ls | grep ".bed" | grep "peaks"

No comments:

Post a Comment