Results 1 to 3 of 3
In Dos you can have wild-cards in the source and destination of your copy. As far as I've been able to work out so-far this isn't possible with a Linux ...
- 05-15-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 2
cp destination wildcards
In Dos you can have wild-cards in the source and destination of your copy. As far as I've been able to work out so-far this isn't possible with a Linux cp command.
What I want to do is roughly as follows.
Given the files:
bo1122peep
bo3884peep
Using a wild-cards in both the source and destination. Retain the wild card information and specify new information for the target.
So the command:
copy bo*pee mad*max
would produce
mad1133max
mad3884max
So do you know of any existing shell scripts that do that? I'd still like to be-able to do -u, -r etc as well.
- 05-16-2007 #2Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
Assume that the variable ofn contains the original file name.Then you can use the following (untested) code snippet:
You can add to cp whichever options you want.Code:case "$ofn" in bo*peep) ofn="${ofn#bo}" ofn="${ofn%peep}" nfn="mad${ofn}max" ;; *) nfn= ;; esac if [ -n "$nfn" ] ; then cp "$ofn" "$nfn" ; fi
Actually the pattern bo*pee does not match the files bo1122peep and bo3884peepGiven the files:
bo1122peep
bo3884peep
Using a wild-cards in both the source and destination. Retain the wild card information and specify new information for the target.
So the command:
copy bo*pee mad*max
would produce
mad1133max
mad3884max
Did you mean to write bo*peep ?
- 05-16-2007 #3Just Joined!
- Join Date
- May 2007
- Posts
- 2
Thanks mate. That's close; but not quite what I was after.
I was kind of angling after a script/command that could cope with a different set of parameters each time, and multiple wild-cards in the destination that could expand at runtime to create multiple input values. Like being able to issue the command cp .* .*-bak to make a backup copy of all your hidden files. However making a command which could cope with all the possibilities is a much bigger job. I was just hoping some-one else had already done it so I wouldn't have to.
Anyway if you know of a more generic cp replacement with -a -r options, and destination wild-cards or even maybe if it is possible with one or more existing commands let me know. I've been thinking about an algorithm for it today so if you don't have any suggestions I might have a crack at writing it myself after all.
cheers


Reply With Quote