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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Files copying - [ Listed files alone. ] - Shell script
# 1  
Old 07-30-2011
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

Code:
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 ]

.
# 2  
Old 07-30-2011
This script should work:
Code:
while read f; do
  new=`echo "$f" | sed 's/MainDir/data/'`
  d=`dirname "$new"`
  mkdir -p "$d" 
  cp -v "$f" "$d"
done <INPUTFILE

This User Gave Thanks to yazu For This Post:
# 3  
Old 07-30-2011
Thanks.. it works fine.Smilie


My svn patch maker is over..!!! Smilie

.
# 4  
Old 07-31-2011
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
Code:
/home/linux/project/MainDir/asp/file1.asp
/home/linux/project/MainDir/java/file3.java


and data in
Code:
/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.. ?
# 5  
Old 07-31-2011
If i understand correctly you have instead MainDir $inputvar with slashes inside and instead of data - $datavar (with slashes too).
Then change
Code:
  new=`echo "$f" | sed 's/MainDir/data/'`

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying the files in to multiple location using shell script

Hi All, i'm trying to copy the 1.txt files (sample files) in to different path location using the below command. But it is not copying the files , when i tried for single location able to copy the file. can any one please assist here. Please find the below path :- /ckr_mkr1/licencekey... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Shell script for connecting multiple servers and then copying 30 days old files

Shell script for connecting multiple servers and then copying 30 days old files from those server . HI , I have 6 multiple servers pla1,pla2,pla3,pla4,pla5,pla6 1. These six servers have common shared mount point /var/share 2. Running script from /var/share to connect these servers.I... (1 Reply)
Discussion started by: rcroyal88
1 Replies

3. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

4. Shell Programming and Scripting

Help with copying files using shell script

I want to write a shell script to copy a list of files from one directory to another. And while copying it should change the first character of the filename to uppercase and others to lowercase.Below is what i have tried so far. for file in "$@" do if then ufile=`echo $file | sed... (5 Replies)
Discussion started by: vishal.desai
5 Replies

5. Shell Programming and Scripting

Shell script for copying files from 1 server to other

Hi, I just need a shell script that copies a list of files from a directory in a remote server to my current directory at local server the remote server may contain the following list: /root/pradeep/myfiles/default /root/pradeep/myfiles/dir1 /root/pradeep/myfiles/dir2 ...... (1 Reply)
Discussion started by: paddu
1 Replies

6. Shell Programming and Scripting

Shell Script to connect to another server and copying files

Hi Unix Gurus, I have a doubt reg file transfer. I have used the below script to connect to another server and find files having modified for the last 24 hours and have to move the file to another server. While i tried i am getting authentication failed, destination path not found issue. ... (2 Replies)
Discussion started by: incepted
2 Replies

7. Shell Programming and Scripting

Cut the first column in listed files > PERL script

Hi All, Using this command wc -l *e* > create2.txt i'm getting the following output >>>create2.txt listed output files, my requirement is how to cut the first coloum in all the files mentioned in create2.txt in perl. 50 allignment.pl 3 create.txt 4 application.txt ... (8 Replies)
Discussion started by: adaleru
8 Replies

8. UNIX for Dummies Questions & Answers

Shell Syntax Error when copying files

Hello, I apologize if this was addressed in a previous post. I have done some searching but may have missed it. I am trying to read a list from a file, for example: 3bik 3bix 3biu 3bin 1nwn and using this list, copy files with these names (ex: 3bik.dssp.Z) to a seperate folder,... (1 Reply)
Discussion started by: InfoSeeker
1 Replies

9. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question