Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I would like to have a new script to perform the below task .
I have a file called dummy.txt , the content of this file is as below .
aaa.prn
bbb.prn
ccc.prn
I would like to have a script which can do
1) check dummy.txt
2) then copy these files ( but with other extension .xls ) from a specify directory to another server
eg. scp the files /tmp/aaa.xls , /tmp/bbb.xls , /tmp/ccc.xls to /tmp of another server
actually , the file name in dummy.txt have two type of prefix , one is xxx ( eg. xxxfile.prn ) , another one is yyy ( eg. yyyfile.prn ) , if the file is xxx , then copy to /tmp of another server , if the file is yyy then copy to /tmp1 of another server , can advise what can i do ?
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
You might want to try giving us some actual examples of filenames and directory trees to work with, rather than trying to describe them.
Use a while+read loop instead. Or read the file into an array first with the mapfile command, and loop over that.
As for your new requirement, I suggest simply adding a case statement to the loop to test the naming pattern of each file, and run the appropriate command.
It would also be a good idea to add some intermediate tests too, to ensure that each file is actually available, as is the target, before trying to move it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.