Reputation: 852
I have a set of files in a single directory named:
OneThing-x.extension
OneThing-y.extension
OneThing-z.extension
What UNIX command (find, cp, xargs, sed ?) do I use to COPY these into
AnotherThing-x.extension
AnotherThing-y.extension
AnotherThing-z.extension
such that x ->copy-> x, and y ->copy -> y
I have the find .. part of the command to start with,which selects the files, but I am stuck there.
EDIT Obviously, I want to keep both the original and the copy, so a rename does not quite do the trick for me.
Upvotes: 2
Views: 1445
Reputation: 13001
You could also use mmv:
$ mmv -c "OneThing*" "AnotherThing#1"
or
$ mmv -c "OneThing-*.extension" "AnotherThing-#1.extension"
Upvotes: 0
Reputation: 52565
How about:
$ touch a1.a a2.a a3.a
$ ls
a1.a a2.a a3.a
$ for a in a*.a ; do cp $a $(echo $a | sed 's/^a/b/') ; done
$ ls
a1.a a2.a a3.a b1.a b2.a b3.a
Upvotes: 3
Reputation: 3583
My rough solution would be something like:
for FIL in OneThing*; do NFIL=`echo $FIL|sed 's/OneThing/AnotherThing/'`; cp "$FIL" "$NFIL"; done;
Upvotes: 1
Reputation: 53320
Extending Jason Musgrove's solution:
for FIL in OneThing*
do
NFIL=`echo $FIL | sed 's/OneThing/AnotherThing/'`
cp "$FIL" "$NFIL"
done
Upvotes: 1