1

so far I have gotten this far:

prompt$ find path/to/project -type f | grep -v '*.ori|*.pte|*.uh|*.mna' | xargs dos2unix 2> log.txt

However, the files with extensions .ori, .pte, .uh and .mna still show up.

Tunaki
  • 116,530
  • 39
  • 281
  • 370
Sassinak
  • 75
  • 1
  • 11

2 Answers2

1

It is better to leave the excluding to find, see Birei's answer.

The problem with your grep pattern is that you have specified it as a shell glob. By default grep expects basic regular expressions (BRE) as its first argument. So if you replace your grep pattern with: .*\.\(ori\|pte\|uh\|mna\)$ it should work. Or if you would rather use extended regular expressions (ERE), you can enable them with -E. Then you can express the same exclusion like this: .*\.(ori|pte|uh|mna)$.

Full command-line:

find . -type f | grep -vE '.*\.(ori|pte|uh|mna)$'
Thor
  • 39,032
  • 10
  • 106
  • 121
  • These didn't work, I wonder why. Does grep not do "filenames only" ? – Sassinak May 15 '13 at 13:42
  • @Sassinak: What command did you run exactly? All `grep` sees are the filenames listed by `find`, one per line if none of them contain newlines in them. So there is no "filenames only" dependence. By the way, you want to match the end of line, so the patterns should be anchored with `$`, I'll add that to the answer. – Thor May 15 '13 at 13:46
  • Okay, added the changes and it works perfectly. I prefer this one because it's "shorter", but the above answer worked as well. Thanks! – Sassinak May 15 '13 at 14:06
1

One way:

find path/to/project *.* -type f ! \( -name '*.ori' -o -name '*.pte' -o -name '*.uh' -o -name '*.mna' \) 
  | xargs dos2unix 2> log.txt
Birei
  • 33,968
  • 2
  • 69
  • 79