I guess this is a typo, isn't it? Should be \; in the end, not +
Hi rovf,
No!
Invokes command once for each file meeting the criteria specified by ..., while:
invokes command once for a group of files meeting the criteria specified by ... with the number of files in the group being determined by the size of the environment passed to command, the length of command, and the length of the pathnames of the files being passed to command.
Quote:
Originally Posted by cola
What's the difference between {} \; and {} + or {} \+ ?
Is it possible to call multiple commands with -exec like piping:
What's wrong with using cat?
The difference between \; and + terminating a find -exec primary is described above.
The command given to a:
or:
primary is something that can be executed by find. The find utility doesn't know how to execute pipelines. You could exec sh -c "pipeline" but the shell's -c operand has to be a single argument so the command you give find won't see the {} (which it will replace with a the name of a found file) as a separate argument, so it might not replace it with the name of a found file. (The standards leave it unspecified whether or not find replaces {} if that string does not appear as a separate argument.)
If you need to use find -exec to run a pipeline (which you DO NOT need to do in this case and doing so would involve running a shell and a cat and a grep when all you need is grep) would be to put the pipeline in a separate shell script such as scriptname containing:
make it executable with:
and move it to some directory in the list of directories in your $PATH environment variable. Then you can execute it with:
If a small number of files is involved, you might get away with having scriptname contain:
and executing it with:
but if the arguments passed to scriptname along with scriptname and its environment is shorter than the command that scriptname will execute, scriptname may fail with a E2BIG error condition unless you build extra argument loop processing to guarantee that the commands being executed by your script won't fail due to the size of the argument list and environment list your shell will be passing to a member of the exec family of functions to run that stage in your pipeline.
Using:
invokes one utility, reads all of the data in file and writes lines in file that contain word while:
invokes two utilities, reads all of the data in file, writes all of the data in file reads all of the data in file again and then writes all of the lines in file that contain word. So the useless use of cat creates an unneeded process, forces the system to read and write the entire contents of file an extra unneeded time wasting system memory, wasting I/O bandwidth, and wasting CPU cycles that could be used by other processes to do something useful. Use cat if you need it; DO NOT use cat if you don't need it! Using cat when you don't need it takes longer for you to get the results you want and wastes system resources that you or someone else on your system might need to use to get something done that needs the cycles you are wasting.
This User Gave Thanks to Don Cragun For This Post:
Hi,
I need to search for a multiple string pattern(5 key words) in a file(similar to a flat file) ,and i need to store the output in a another file .
In that file we may have mutiple occurrences of the key words.and i need only the unique.
kindly help out.
Thanks,
Mohana Krishnan (2 Replies)
Hi,
I am new to Unix world. Is there any command which can directly return the second occurance of a particular string in a file? Basically, I want to read the contents of the file from the second occurance of a particualr string. Can be implemented using a loop, but am just wondering if there... (5 Replies)
Hi ,
I have a directory structure as dir and subdirectories and files under it and so on.now I need to find the files which contain the search string under every dir and subdir and replace .
my search string is like
searchstring=/a/b
string to be replaced=/a/c/b
please help.
... (7 Replies)
Hi
i am having a group of *.csh files under parent directory. Now i want to search a particular pattern in these group of *.csh files(suppose i need to search a pattern ABC - proj ). Can anyone please tell me how to do it using find command.
Thanks in advance
sarbjit (4 Replies)
I've got a semicolon delimited file. I would like to search for fields that match a pattern, and not hardcoded eg "mth".
*th=something
If the delimited field fulfills this condition, eg. mth=value
I would like to print out both key and value for some number comparison.
eg. if value > "12"... (5 Replies)
Hi,
Need your help in this.
I have an input file that has multiple enrollment_number, somewhat like
1234567
8901234
9856321
6732187
7623465
Now i have to search and delete these enrollment_number recursively from all the files that are within multiple sub-directories of a... (10 Replies)
I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported
Input file is a free flowing file without any format
example of output
ERR-00001=5
....
ERR-01010=10
.....
ERR-99999=10 (4 Replies)
i have a file named keyword.csv(contains around 8k records) which contains a no. of columns.
The 5th column contains all the keywords.
I want to recursively search these keywords in all .pl files(around 1k) and display the filename....Afterthat i will use the filename and some of the column from... (3 Replies)
Hi All,
I hope somebody would be able to help me.
I would need to search a string coming from a file, example file.txt:
dog
cat
goat
horse
fish
For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Experts,
Need your support for this awk script.
we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file
Need to grep row whose string contains 9K from column 1. When found... (6 Replies)