Rename a specific component of filename from lowercase to uppercase
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a directory with several files named as follow:
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
London_qle_obs
Paris_qle_merged
Tokyo_qle_merged
How can I rename the file having *merged in the filename as follow:
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
I know that I could do a loop as follow:
for name in Paris London Tokyo do;
mv $name_qle_merged $name_Qle_merged
done
but is there no other way?
mv
add a comment |Â
up vote
0
down vote
favorite
I have a directory with several files named as follow:
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
London_qle_obs
Paris_qle_merged
Tokyo_qle_merged
How can I rename the file having *merged in the filename as follow:
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
I know that I could do a loop as follow:
for name in Paris London Tokyo do;
mv $name_qle_merged $name_Qle_merged
done
but is there no other way?
mv
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a directory with several files named as follow:
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
London_qle_obs
Paris_qle_merged
Tokyo_qle_merged
How can I rename the file having *merged in the filename as follow:
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
I know that I could do a loop as follow:
for name in Paris London Tokyo do;
mv $name_qle_merged $name_Qle_merged
done
but is there no other way?
mv
I have a directory with several files named as follow:
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
London_qle_obs
Paris_qle_merged
Tokyo_qle_merged
How can I rename the file having *merged in the filename as follow:
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
I know that I could do a loop as follow:
for name in Paris London Tokyo do;
mv $name_qle_merged $name_Qle_merged
done
but is there no other way?
mv
edited Jan 31 at 20:13
user1404316
2,314520
2,314520
asked Jan 31 at 15:39
steve
328211
328211
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
2
down vote
accepted
Sure. In ksh/Bash/zsh:
for f in *_merged; do
mv -- "$f" "$f/_qle_/_Qle_"
done
or in standard shell.
for f in *_qle_merged; do
mv -- "$f" "$f%_qle_merged_Qle_merged"
done
See also, e.g. Parameter Expansion in BashGuide
add a comment |Â
up vote
0
down vote
I have done this by combination of awk and tr
Command
find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh
Below merged files
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
renamed to
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
add a comment |Â
up vote
0
down vote
This will do the job with no script loops, spawning just a single sub-process:
rename 's/qle/Qle/' *_merged
add a comment |Â
up vote
0
down vote
The rename
command is your friend here. It is sed
for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).
The following answer is for file content, and thus uses sed
. I have used it and re-purposed it to rename
.
https://unix.stackexchange.com/a/211579/4778
rename -e 's/_(.)/_u$1/' *_merged
It up cases the letter immediately following the first _
.
A simpler solution for this specific input
rename 's/qle/Qle/' *_merged
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Sure. In ksh/Bash/zsh:
for f in *_merged; do
mv -- "$f" "$f/_qle_/_Qle_"
done
or in standard shell.
for f in *_qle_merged; do
mv -- "$f" "$f%_qle_merged_Qle_merged"
done
See also, e.g. Parameter Expansion in BashGuide
add a comment |Â
up vote
2
down vote
accepted
Sure. In ksh/Bash/zsh:
for f in *_merged; do
mv -- "$f" "$f/_qle_/_Qle_"
done
or in standard shell.
for f in *_qle_merged; do
mv -- "$f" "$f%_qle_merged_Qle_merged"
done
See also, e.g. Parameter Expansion in BashGuide
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Sure. In ksh/Bash/zsh:
for f in *_merged; do
mv -- "$f" "$f/_qle_/_Qle_"
done
or in standard shell.
for f in *_qle_merged; do
mv -- "$f" "$f%_qle_merged_Qle_merged"
done
See also, e.g. Parameter Expansion in BashGuide
Sure. In ksh/Bash/zsh:
for f in *_merged; do
mv -- "$f" "$f/_qle_/_Qle_"
done
or in standard shell.
for f in *_qle_merged; do
mv -- "$f" "$f%_qle_merged_Qle_merged"
done
See also, e.g. Parameter Expansion in BashGuide
answered Jan 31 at 15:42
ilkkachu
49.8k674137
49.8k674137
add a comment |Â
add a comment |Â
up vote
0
down vote
I have done this by combination of awk and tr
Command
find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh
Below merged files
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
renamed to
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
add a comment |Â
up vote
0
down vote
I have done this by combination of awk and tr
Command
find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh
Below merged files
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
renamed to
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have done this by combination of awk and tr
Command
find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh
Below merged files
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
renamed to
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
I have done this by combination of awk and tr
Command
find . -type f -iname "*merged" |tr -d "./" | awk -F "_" 'print "mv" " " $1"_"$2"_"$3 " " $1"_"toupper(substr($2,1,1))substr($2,2)"_"$3 ' | sh
Below merged files
London_qle_merged
Paris_qle_merged
Tokyo_qle_merged
renamed to
London_Qle_merged
Paris_Qle_merged
Tokyo_Qle_merged
answered Jan 31 at 18:52
Praveen Kumar BS
1,010128
1,010128
add a comment |Â
add a comment |Â
up vote
0
down vote
This will do the job with no script loops, spawning just a single sub-process:
rename 's/qle/Qle/' *_merged
add a comment |Â
up vote
0
down vote
This will do the job with no script loops, spawning just a single sub-process:
rename 's/qle/Qle/' *_merged
add a comment |Â
up vote
0
down vote
up vote
0
down vote
This will do the job with no script loops, spawning just a single sub-process:
rename 's/qle/Qle/' *_merged
This will do the job with no script loops, spawning just a single sub-process:
rename 's/qle/Qle/' *_merged
answered Jan 31 at 19:09
user1404316
2,314520
2,314520
add a comment |Â
add a comment |Â
up vote
0
down vote
The rename
command is your friend here. It is sed
for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).
The following answer is for file content, and thus uses sed
. I have used it and re-purposed it to rename
.
https://unix.stackexchange.com/a/211579/4778
rename -e 's/_(.)/_u$1/' *_merged
It up cases the letter immediately following the first _
.
A simpler solution for this specific input
rename 's/qle/Qle/' *_merged
add a comment |Â
up vote
0
down vote
The rename
command is your friend here. It is sed
for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).
The following answer is for file content, and thus uses sed
. I have used it and re-purposed it to rename
.
https://unix.stackexchange.com/a/211579/4778
rename -e 's/_(.)/_u$1/' *_merged
It up cases the letter immediately following the first _
.
A simpler solution for this specific input
rename 's/qle/Qle/' *_merged
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The rename
command is your friend here. It is sed
for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).
The following answer is for file content, and thus uses sed
. I have used it and re-purposed it to rename
.
https://unix.stackexchange.com/a/211579/4778
rename -e 's/_(.)/_u$1/' *_merged
It up cases the letter immediately following the first _
.
A simpler solution for this specific input
rename 's/qle/Qle/' *_merged
The rename
command is your friend here. It is sed
for file names. (ensure that you have the Larry Wall version, there is at least two programs with this name).
The following answer is for file content, and thus uses sed
. I have used it and re-purposed it to rename
.
https://unix.stackexchange.com/a/211579/4778
rename -e 's/_(.)/_u$1/' *_merged
It up cases the letter immediately following the first _
.
A simpler solution for this specific input
rename 's/qle/Qle/' *_merged
answered Jan 31 at 19:19
ctrl-alt-delor
8,79031947
8,79031947
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%2f420988%2frename-a-specific-component-of-filename-from-lowercase-to-uppercase%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