unix find utility
I use the 'find' command alot, but I always get stuck on the fact that I can't get the pipe operator to work in the -exec option. Here is what I want to do
find -name -exec echo {} | grep -o whatever \; This isn't actually what I am doing, but an example. So basically whenever I do this everything after the pipe just gets ignored. I would like each found file to be properly piped into grep -o. \| and '|' and "|" don't work. Is there an escape sequence to get the pipe to work properly there? |
hi there,
Quote:
something like this... Code:
find -name -print $something | xargs echo .... | ... regards, slackie1000 |
find -name -exec grep -o whatever {} \;
but I don't think that's what you mean. However find -name | xargs grep whatever should also work. |
Quote:
Code:
find . -name '*whatever*' | grep -o whatever edit2: You didn't specify a directory in yours.. I added one to mine above. |
more specifically
lets say I want to change the extensions on a group of files, say a bunch of jpegs from jpg to jpeg. So I cd to the directory and then I would like to do:
Code:
find . -type d -maxdepth 1 -mindepth 1 -exec cp -v {} "$(echo {} | grep -o '*.\.')" \; |
-type d won't grab too many jpeg files. And if you 'cd' to the directory, then something like 'for f in *jpg; do mv $f ${f%%.*}.jpeg; done' might suffice. Which has nothing to do with find and pipes but is a way to handle your example. How about citing an actual case? You don't have to use xargs - you can just do a for loop with find or whatever you want. There's a million ways to do stuff, so it's hard to guess which corners of your cases you don't like.
|
for loop...
A for loop could work. This is what I am doing. I am trying to change extensions of files, to be uniform. The type d was a typo on my part, I always run the find before I actually try to run the find -exec, I meant to put type f. I will try the for loop, I just like the find, since it is more flexible. This is mainly just a pet peeve since I use find all the time, yet I can never get the pipes to work. I have written scripts to get around it before, but I just thought someone might know a better way.
|
for file in `ls`
do mv $file $file.JPG done ...you could do for file in `find ....` cheers :) |
Quote:
|
All times are GMT -5. The time now is 12:20 AM. |