I just thought I had found my solution because the command works in my test directory.
grep -H -e 'author="[^"].*' *.xml | cut -d: -f1 | xargs -I '{}' mv {} mydir/.
But using the command in the non-test-direcory the command did not work:
This is the error message:
grep: unknown option -- O Usage: grep [OPTION]... PATTERN [FILE]... Try `grep --help' for more information.
Not even this worked:
$ grep -H author *.xml
or this:
$ grep -H 'author' *.xml
(same error message)
I suspect it has some relation to the file names or the amount of files.
I have almost 3000 files in the non-test-directory and only 20 in my test directory.
In both directories almost all file names contain spaces and ” – “.
Some more info:
- I’m using Cygwin.
- I am not allowed to change the filenames
Try this (updated):
EXPLANATION (updated)
In your “real” directory you have a file with name starting with
-O.Your shell expands the file list
*.xmlandgreptakes your-starting filename as an option (not valid). Same thing happens withmv. As explained in theCommon optionssection ofinfo coreutils, you can use--to delimit the option list. What comes after--is considered as an operand, not an option.Using the
-l(lowercase L) option,grepoutputs only the filename of matching files, so you don’t need to usecut.To correctly handle every strange filename, you have to use the pair
-Zingrepand-0inxargs.No need to use
-ebecause your pattern does not begin with-.Hope this will help!