Shell Syntax Error when copying files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell Syntax Error when copying files
# 1  
Old 11-13-2008
Java 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:

Code:
3bik
3bix
3biu
3bin
1nwn

and using this list, copy files with these names (ex: 3bik.dssp.Z) to a seperate folder, named Subset. [Kindly note that all files have the same .dssp.Z extension, they only differ in the names!]

I have written this code below but keep getting syntax errors...could you kindly tell me what I am doing wrong? I am new to scripting and I apologize in advance for any silly errors!
The code:

Code:
 
#!/bin/bash
cat file.txt | while read Line;
do
cp $Line.dssp.Z /Subset
done

I have saved this as Test.sh
My understanding now is that I simply call:
bash Test.sh
in the commandline (MacOs by the way)

Please correct me if I'm wrong, and let me know if the logic of the code is correct also.
Many thanks,
InfoSeeker
# 2  
Old 11-13-2008
When posting about getting errors, post the errors, even for a simple script, it's much easier for people to help if you do.

It is not a good idea to cat a file into a while loop because you will break the script is any files have spaces in their names although the script looks like it should have worked. Thy adding the {..} to $Line as below in case you are getting some kind of misinterpretation of the variable name, or you might have blank lines in the input file.

Code:
#!/bin/bash
while read Line ; do
     cp ${Line}.dssp.Z /Subset
done < file.txt

 
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

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

3. 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

4. Solaris

Error copying files

I have installed Solaris 10 on a Sunblade 150 (512 MB RAM) successfully. But when I create a new directory and try to copy a 40 MB file to it it stops after about 37 MB and gives an error "I/O error" while copying. I have 40GB of Hard Disk. What is the problem? (8 Replies)
Discussion started by: mickod
8 Replies

5. Shell Programming and Scripting

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 ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

6. 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

7. 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

8. UNIX for Advanced & Expert Users

getting error while copying files

I am trying copy all files ,i was getting below error .Please any idea #find . -name "*bat" -exec cp -p {} /devt/jobs find: incomplete statement Thanks, Akil (9 Replies)
Discussion started by: akil
9 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 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