2

How can I get modules/bx/motif only on the following through pipeline?

$ find . | grep denied
find: `modules/bx/motif': Permission denied
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
caot
  • 3,066
  • 35
  • 37

2 Answers2

1

You can redirect STDOUT (where the errors you want appear) so you can process it with other tools, then throw away STDIN (which contains non-errors that you don't care about) then use cut (or any of a hundred other methods) to pull out the bits you need:

find . 2>&1 >/dev/null | cut -d"‘" -f2 | cut -d"’" -f1

You might also be able to use one of the built-in find filters (like -perm maybe) to pick out these files, but you'll have to check the findq man page for details.

find . -not -readable might be helpful in your case.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
1

Simply this, using sed:

find . 2>&1 | sed 's/^[^:]*: .\(.*\).: Permission denied/\1/p;d'

or by using only,

As your question stand for :

string=$'find: `modules/bx/motif\047: Permission denied'
echo $string 
find: `modules/bx/motif': Permission denied

part=${string#*\`} 
echo ${part%\'*}
modules/bx/motif
F. Hauri - Give Up GitHub
  • 64,122
  • 17
  • 116
  • 137
  • The first line of code is perfect. added another question to pipeline to sudo chmod https://stackoverflow.com/questions/49432555/how-to-pipeline-permission-denied-file-folders-into-sudo-chmod-orw . You might be able to help. Thanks so much! – caot Mar 22 '18 at 15:29