1

I have a file, FileToCopy.pbs, that I would like to copy into multiple directories while changing a line called xxx in the file to the pwd location of the directory in which the file is to be copied.

What kind of for loop can I use to make this command?

Also, some of my directories include a * at the end of the directory path name.

More specifically I have a directory structure:

/home/path1/dir1
/home/path1/dir2
/home/path1/dir3*
/home/path1/dir4*
.
.
etc

and would like to copy FileToCopy.pbs into all directories so that I have:

/home/path1/dir1/FileToCopy.pbs
/home/path1/dir2/FileToCopy.pbs
/home/path1/dir3*/FileToCopy.pbs
/home/path1/dir4*/FileToCopy.pbs

while changing a line xxx in each copied file of FileToCopy.pbs to the directory in which it is in. For instance, the line xxx for the FileToCopy.pbs located in /home/path1/dir1/ should be changed to /home/path1/dir1/

Thank you.

1 Answer 1

1

I have figured it out.

The code is as follows:

In the directory /home/path1/

for i in *; do cp /directory/of/FileToCopy.pbs $i; cd $i; sed -i s#xxx#$(pwd)#g FileToCopy.pbs ; cd /home/path1/; done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .