Visit Our UNIX and Linux User Community

Compound command with 'find' utility?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compound command with 'find' utility?
# 1  
Old 10-04-2005
Compound command with 'find' utility?

I'm trying to write a script using the 'find' command and it's -exec option to run a compound command against the files found.


find . -name "*.conf" -exec cat {} | grep "#" > /tmp/comments.list \;

Of course the above doesn't work. So I experimented for a bit to see if there was some way to group the commands together with ( ) or by quoting the command. But the results weren't useful. So, at this point the only option I have been able to think of is to write a separate script and call it with -exec. But I really would like to have everything in one script. Is it possible to execute a compound command line with -exec? Or am I tilting at windmills?
# 2  
Old 10-04-2005
At a minum you could revise your find to something like this:

find . -name "*.conf" | xargs cat | grep "#" > /tmp/comments.list
# 3  
Old 10-04-2005
This is UUOC. Just use
find . -name "*.conf"  -exec grep "#" {} \; > /tmp/comments.list

# 4  
Old 10-04-2005
this works.

find . -name "vg*.*" -exec grep vg {} \;

Or in your case...

find . -name "*.conf" -exec grep "\#" {} \;
# 5  
Old 10-04-2005
More Info About My Case...

Well... I think I should have stated that the example I posted was an example of a type of use for -exec. But it's not the use I am wanting.

I have a need to use 'find' to locate some files. Once those files are found one at a time, I need each to be processed with a long compound command line or possibly multiple commands to write some metadata into the file using variables.

Closer example to reality:

find . -name "*.fil" -exec metafiler -t METADATA1="First Tag" {} -exec metafiler -t METADATA2="Second Tag" {} -exec metfiler -t METADATA3="Third Tag" {} \;

Does that make more sense?
# 6  
Old 10-04-2005
Sometimes I do this....
find . -print | while read filename ; do
      echo process $filename

# 7  
Old 10-05-2005
MySQL That works!

Thanks Perderabo! It's a different approach than what I was originally thinking, but it will allow me to accomplish what is needed.

Previous Thread | Next Thread
Test Your Knowledge in Computers #628
Difficulty: Easy
In PHP, True !== 1;
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

behavior of find utility's -mtime -7 primary

Can I ask a question not related to original question. I have this below command running on a directory which contains thousands of files. This command runs for 5 minutes. Any files received in folder1 during the execution of command is getting moved, even though that file is just received and it's... (6 Replies)
Discussion started by: Super123
6 Replies

2. AIX

Help to find isutf8 utility for AIX 6.1

Hello everyone, I need to validate the file format for the UTF-8 standard. I know that "isutf8"utility is a part of "moreutils" pkg, I was able to find this package for the Linux but my environment in the AIX 6.1. I would be greatly appreciate your suggestion to my search. I am not familiar with... (5 Replies)
Discussion started by: Nadya Chipova
5 Replies

3. Homework & Coursework Questions

About menu using dd command utility

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Please help about these script... i dont have a problem in option 1. But when it comes to options 2 and options 3... (2 Replies)
Discussion started by: amneytia1
2 Replies

4. Homework & Coursework Questions

How to invent new command utility

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Develop a utility that will enhance the current file management and organization functions of Linux. You... (3 Replies)
Discussion started by: stephanielana1
3 Replies

5. Shell Programming and Scripting

DB Access Command Line Utility

To read/write to a DB from Java or Perl, you usually have to install/reference several drivers and write a whole bunch of boilerplate DB access code. I'm curious if someone has written a command line utility for Unix/Linux for simple database access for the major providers, something like: ... (3 Replies)
Discussion started by: furashgf
3 Replies

6. Linux

The dot command-line utility?

Hi, What else is the dot used beside relative filepaths in bash? Is it a shell utility as well? No man entry for dot (.)... (3 Replies)
Discussion started by: varelg
3 Replies

7. Shell Programming and Scripting

Question on Find Utility

Hi Guys, Do you know how can I find files with modificatioin time less than 30 MINUTES using the find utility? Or if u have any other mechanism to find it using script, I'll appreciate it. Thanks! (5 Replies)
Discussion started by: marlonus999
5 Replies

8. Shell Programming and Scripting

options in FIND utility

hi folks, I want to select all files older than 13 days from a specified directory for that i used find /home/amar -name '*.*' -mtime 13 but it gives me all the files from subdirectories also, I dont want that I want files only from /home/amar and not from /home/amar/abc/.. which... (8 Replies)
Discussion started by: amarnath
8 Replies

9. UNIX for Dummies Questions & Answers

can't find my NEDIT utility after shell change

Hello, My System Admin. just switched me from KSH to BASH and something happened to my "nedit" utility! Does anyone know how to reactivate nedit by anychance? Thanks very much! BobK (2 Replies)
Discussion started by: bobk544
2 Replies

10. Programming

Threaded 'find' utility

I need to modify my version of find in unix and get it to create and use two POSIX threads to carry out concurrent finding operations. How do i get about doing this>? If anyone could help me it would be much appreciated. Thanx Mariuca (1 Reply)
Discussion started by: mariuca
1 Replies

Featured Tech Videos