Solved

Copy files with different names

Posted on 2006-11-01
1
256 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

803 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