Here's one way of doing this using the standard Linux utils
source <(find . -type f -name "*.1" | sed -nr "s/(^.*)\.(.*)\.1/mv \1.\2.1 \1.\2/p")
Explanation:
source <(CMD)
CMD
find . -type f -name "*.1"
.1
sed -nr "s/(^.*)\.(.*)\.1/mv \1.\2.1 \1.\2/p"
source
We can also use exec option from find itself but I didn't go down that path :)
exec
Neat! Thanks for sharing π you could also do it in pure Bash with a for loop and string indexing. But itβs not as nifty as your way.
Yes. Another way I found was using awk instead of source as follows:
awk
find . -type f -name "*.1" | sed -nr "s/(^.*)\.(.*)\.1/mv \1.\2.1 \1.\2/p" | awk '{system($0)}'
This makes the eval of strings part of the pipeline.
eval
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here's one way of doing this using the standard Linux utils
Explanation:
source <(CMD)
executes text output ofCMD
as a command.find . -type f -name "*.1"
finds all files in current directory ending with.1
sed -nr "s/(^.*)\.(.*)\.1/mv \1.\2.1 \1.\2/p"
uses a regex to get the basename and extension before.1
and outputs a move command with.1
removed.source
We can also use
exec
option from find itself but I didn't go down that path :)Neat! Thanks for sharing π you could also do it in pure Bash with a for loop and string indexing. But itβs not as nifty as your way.
Yes. Another way I found was using
awk
instead ofsource
as follows:This makes the
eval
of strings part of the pipeline.