Files copying - [ Listed files alone. ] - Shell script

Hi All,

I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files.

To Do
From Directory : /myproject/MainDir
To Directory : /myproject/data

List of files need to copy is in the file: /myproject/filesList.txt

cat /myproject/filesList.txt              input
/myproject/MainDir/class2/c/nnnn.java
/myproject/MainDir/class1/a/zyx.java
/myproject/MainDir/class1/b/nnnn.java
/myproject/MainDir/class1/b/hh.java

Directory structure
MainDir
class1
a
abc.java
zyx.java
b
hh.java
nnnn.java
c
class2
a
a.java
hhhh.java
b
hhhh.java
zyx.java
c
nnnn.java
d
e
class3
aa
dd
system
system123
pp

Now the thing i needed is :
I want all the ONLY files listed in filesList.txt to be copied in /myproject/data with the same path.

So that the output will be all the files copied as ::
/myproject/data/class2/c/nnnn.java
/myproject/data/class1/a/zyx.java
/myproject/data/class1/b/nnnn.java
/myproject/data/class1/b/hh.java

is it possible..?

[ pls tell me if my doubt is not clear ]

.

This script should work:

while read f; do
  new=`echo "$f" | sed 's/MainDir/data/'`
  d=`dirname "$new"`
  mkdir -p "$d" 
  cp -v "$f" "$d"
done <INPUTFILE
1 Like

Thanks.. it works fine.:b:

My svn patch maker is over..!!! :slight_smile:

.

Dear Yazu..

sorry to say that i didnt understand your code completely. I tried its working fine in "Dummy directory" what i given. Thanks for that.

Actually my MainDir will be in one path and data directory will be in another path.

Eg: MainDir is like

/home/linux/project/MainDir/asp/file1.asp
/home/linux/project/MainDir/java/file3.java

and data in

/var/myfolder/data

If i do this spec with your code , i am getting error. Can you make it clear , if possible with variables ?
I mean
inputvar="/home/linux/project/MainDir"
outputvar="/var/myfolder/data"

What we shall do.. ?

If i understand correctly you have instead MainDir $inputvar with slashes inside and instead of data - $datavar (with slashes too).
Then change

  new=`echo "$f" | sed 's/MainDir/data/'`

to

 new = `echo "$f" | sed "s!$inputvar!$datavar!"