Question: I have some text files in a directory. I would like to read all the files in this directory and if the file has the following line

`SAMPLE 350 AN INTEGER OF TYPE :DECIMAL : CAN BE ASSEMBLED BY` move that file with its all contents to another directory.

How can I do this?

Answer: 
Using `find` and `grep`:

```
$ find . -type f -exec \
  fgrep -l "SAMPLE 350 AN INTEGER OF TYPE :DECIMAL : CAN BE ASSEMBLED BY" {} \; \
  | xargs -i%  mv % /path/to/new/dir

```
This is easy in bash:

```
grep -l "PATTERN" *

```

gives you a list of files that contains PATTERN in current directory. So unless you have too many files you could do:

```
mv `grep -l "SAMPLE 350 AN INTEGER OF TYPE :DECIMAL : CAN BE ASSEMBLED BY"` /another/directory

```

The back ticks (they are no normal quotes) executes the command and replaces it with the output (in this case with the list of files). Instead of the back ticks you can use $(command). So you can just as well write:

```
mv $(grep -l "SAMPLE 350 AN INTEGER OF TYPE :DECIMAL : CAN BE ASSEMBLED BY") /another/directory

```

If you have alot of files, bash might not be able to expand that many files (you will reach the limit of how big your command will be...it is alot). You must then resort to xargs:

```
grep -l "SAMPLE 350 AN INTEGER OF TYPE :DECIMAL : CAN BE ASSEMBLED BY" | xargs -i mv {} /another/directory

```

The -i to xargs means that it will take one line at a time from the output from grep (a matching filename) and where the {} are will be expanded to that text and the command will run.