Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FIND & exec 2

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
Hi,

I have to append the content of the file myfil.txt to each *.scr file found in every sub-folder under the main directory "maindir"
Each *.scr file has a unique name. Someone in the forum suggested the following command:
find maindir -name *.scr -exec cat /path/to/myfil.txt >> {} \;

But, what this command does is, it writes out the content of myfil.txt to a file by name "{}", therefore, I can't use it.
Can somebody please help me how this can be done.

My directory-tree is as follows:

MAIN DIRECTORY
|
|
|----|-------|---|---|---|
| | | |
sub1 sub2 sub3 .......subn
| | | |
| xyz.scr | |
abc.scr cbc.scr wxy.scr


Thanks, Thanks in advance!

RV
 
Hi,

I would have given the same solution as above,
but I just tried, and it doesn't work.
Strange.

A quick workaround could be:
(untested!)

Create a file called append.sh,
which essentially consists of this line:
cat /path/to/myfil.txt >> $1

then modify your find command:
find maindir -name *.scr -exec /path/to/append.sh {} \;

hth
 
find maindir -name '*.scr' | while read f; do cat /path/to/myfil.txt >> "$f"; done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top