tags:

views:

166

answers:

2

Hello everybody

I am trying to exclude a certain string from a file search.

Suppose I have a list of files: file_Michael.txt, file_Thomas.txt, file_Anne.txt.

I want to be able and write something like

ls *<and not Thomas>.txt

to give me file_Michael.txt and file_Anne.txt, but not file_Thomas.txt.

The reverse is easy:

ls *Thomas.txt

Doing it with a single character is also easy:

ls *[^s].txt

But how to do it with a string?

Sebastian

+1  A: 

with bash

shopt -s extglob
ls !(*Thomas).txt

some other ways

find . -type f \( -iname "*.txt" -a -not -iname "*thomas*" \)

ls *txt |grep -vi "thomas"
ghostdog74
Thanks for the answer. What does the first line mean?
steigers
the first line mean set extended globbing. see http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching for more
ghostdog74
+2  A: 

You can use find to do this:

$ find . -name '*.txt' -a ! -name '*Thomas.txt'
Mark Byers
Thanks, that's what I needed.
steigers