Copy files and replace token in the filename?

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I've been doing Project Euler for a long time. I have a project structure that makes it really easy to create a new folder for the next question and I have a couple of boilerplate golang files to get started with.
ProjectEuler/001/001.go
ProjectEuler/001/001_test.go
ProjectEuler/002/002.go
ProjectEuler/002/002_test.go
...
ProjectEuler/new_question_stub/xxx.go
ProjectEuler/new_question_stub/xxx_test.go
When I create a new question's folder, I run these commands:
ProjectEuler $ mkdir 003
ProjectEuler $ cd 003
ProjectEuler/003 $ cp ../new_question_stub/xxx.go 003.go
ProjectEuler/003 $ cp ../new_question_stub/xxx_test.go 003_test.go
I feel there should be some way to say "copy every file out of a specific directory to the current directory, but replace token xxx with 003." It doesn't have to be one command to copy and rename in one stroke. Copying them all is easy enough but how would I rename them all after they're copied?
Edit: my use case is a pretty trivial example of only two files but I'm looking for a way to do it for an arbitrary number of files.
command-line
add a comment |Â
up vote
2
down vote
favorite
I've been doing Project Euler for a long time. I have a project structure that makes it really easy to create a new folder for the next question and I have a couple of boilerplate golang files to get started with.
ProjectEuler/001/001.go
ProjectEuler/001/001_test.go
ProjectEuler/002/002.go
ProjectEuler/002/002_test.go
...
ProjectEuler/new_question_stub/xxx.go
ProjectEuler/new_question_stub/xxx_test.go
When I create a new question's folder, I run these commands:
ProjectEuler $ mkdir 003
ProjectEuler $ cd 003
ProjectEuler/003 $ cp ../new_question_stub/xxx.go 003.go
ProjectEuler/003 $ cp ../new_question_stub/xxx_test.go 003_test.go
I feel there should be some way to say "copy every file out of a specific directory to the current directory, but replace token xxx with 003." It doesn't have to be one command to copy and rename in one stroke. Copying them all is easy enough but how would I rename them all after they're copied?
Edit: my use case is a pretty trivial example of only two files but I'm looking for a way to do it for an arbitrary number of files.
command-line
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I've been doing Project Euler for a long time. I have a project structure that makes it really easy to create a new folder for the next question and I have a couple of boilerplate golang files to get started with.
ProjectEuler/001/001.go
ProjectEuler/001/001_test.go
ProjectEuler/002/002.go
ProjectEuler/002/002_test.go
...
ProjectEuler/new_question_stub/xxx.go
ProjectEuler/new_question_stub/xxx_test.go
When I create a new question's folder, I run these commands:
ProjectEuler $ mkdir 003
ProjectEuler $ cd 003
ProjectEuler/003 $ cp ../new_question_stub/xxx.go 003.go
ProjectEuler/003 $ cp ../new_question_stub/xxx_test.go 003_test.go
I feel there should be some way to say "copy every file out of a specific directory to the current directory, but replace token xxx with 003." It doesn't have to be one command to copy and rename in one stroke. Copying them all is easy enough but how would I rename them all after they're copied?
Edit: my use case is a pretty trivial example of only two files but I'm looking for a way to do it for an arbitrary number of files.
command-line
I've been doing Project Euler for a long time. I have a project structure that makes it really easy to create a new folder for the next question and I have a couple of boilerplate golang files to get started with.
ProjectEuler/001/001.go
ProjectEuler/001/001_test.go
ProjectEuler/002/002.go
ProjectEuler/002/002_test.go
...
ProjectEuler/new_question_stub/xxx.go
ProjectEuler/new_question_stub/xxx_test.go
When I create a new question's folder, I run these commands:
ProjectEuler $ mkdir 003
ProjectEuler $ cd 003
ProjectEuler/003 $ cp ../new_question_stub/xxx.go 003.go
ProjectEuler/003 $ cp ../new_question_stub/xxx_test.go 003_test.go
I feel there should be some way to say "copy every file out of a specific directory to the current directory, but replace token xxx with 003." It doesn't have to be one command to copy and rename in one stroke. Copying them all is easy enough but how would I rename them all after they're copied?
Edit: my use case is a pretty trivial example of only two files but I'm looking for a way to do it for an arbitrary number of files.
command-line
edited Apr 3 at 15:15
asked Apr 3 at 15:06
Corey Ogburn
152110
152110
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
Okay with using a for loop? Like
for file in ../new_question_stub/*; do cp "$file" "003$file#*xxx"; done
Maybe you want to define a function for this
add a comment |Â
up vote
-1
down vote
You can first copy all xxx_* files and then use perl rename to rename them:
rename "s,^xxx,"$(basename $(pwd))"," *
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Okay with using a for loop? Like
for file in ../new_question_stub/*; do cp "$file" "003$file#*xxx"; done
Maybe you want to define a function for this
add a comment |Â
up vote
0
down vote
Okay with using a for loop? Like
for file in ../new_question_stub/*; do cp "$file" "003$file#*xxx"; done
Maybe you want to define a function for this
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Okay with using a for loop? Like
for file in ../new_question_stub/*; do cp "$file" "003$file#*xxx"; done
Maybe you want to define a function for this
Okay with using a for loop? Like
for file in ../new_question_stub/*; do cp "$file" "003$file#*xxx"; done
Maybe you want to define a function for this
answered Apr 3 at 15:23
Philippos
5,90211545
5,90211545
add a comment |Â
add a comment |Â
up vote
-1
down vote
You can first copy all xxx_* files and then use perl rename to rename them:
rename "s,^xxx,"$(basename $(pwd))"," *
add a comment |Â
up vote
-1
down vote
You can first copy all xxx_* files and then use perl rename to rename them:
rename "s,^xxx,"$(basename $(pwd))"," *
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
You can first copy all xxx_* files and then use perl rename to rename them:
rename "s,^xxx,"$(basename $(pwd))"," *
You can first copy all xxx_* files and then use perl rename to rename them:
rename "s,^xxx,"$(basename $(pwd))"," *
edited Apr 3 at 15:22
answered Apr 3 at 15:11
Arkadiusz Drabczyk
7,18521532
7,18521532
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435300%2fcopy-files-and-replace-token-in-the-filename%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password