Solved

Copy files with different names

Posted on 2006-11-01
1
246 Views
Last Modified: 2010-04-21
I’m trying to copy files from directory “dirA” to another directory “dirB”.  In dirA I have a number of files which have same names but different extensions:
-      opt0000.wav
-      opt0000.gsm
-      opt0000.txt
There aren’t always three files, sometimes there is only wav and gsm, sometimes there is only gsm and txt and so on, so the only constant I can rely on is the name “opt0000”.

Now, I’m trying to copy these files to dirB, however, the problem is that I need to be able to change the name from opt0000 to, for example, opt0020, so I can’t use “cp dirA/opt0000* dirB/.”.

Is there a command that can do something like this?

Thanks,
Kate
0
Comment
Question by:kasiencja
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17854321
perl -e '$x=$_,s#dirA/opt0000#dirB/opt0020#,system"cp $x $_" for <dirA/opt0000*>'
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now