问题
How can I get modules/bx/motif
only on the following through pipeline?
$ find . | grep denied
find: `modules/bx/motif': Permission denied
回答1:
Simply this, using sed
:
find . 2>&1 | sed 's/^[^:]*: .\(.*\).: Permission denied/\1/p;d'
or by using bash only,
As your question stand for bash:
string=$'find: `modules/bx/motif\047: Permission denied'
echo $string
find: `modules/bx/motif': Permission denied
part=${string#*\`}
echo ${part%\'*}
modules/bx/motif
回答2:
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 find
q man page for details.
find . -not -readable
might be helpful in your case.
来源:https://stackoverflow.com/questions/49431602/how-do-i-split-a-string-on-a-delimiter-in-bash