I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
I once faced a similar issue. My boss, who isn't an IT guy at all, wanted to change the extension of many files. He told me to do it (for I was the new hire then). All the files had a common extension. I did not have to write a code to automate it, I just opened cmd and used the command (rename *.zip *.xlsx)
that's it!
As I was reading through your post, this solution kept popping up in my mind. But then I realized that you had different extensions to change.
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
Yeah, it would have been a lot easier if I hadn't needed to preserve some amount of the original extension. But definitely a PowerShell one-liner was my first thought.
Python is such an awesome glue/hack language. I love your storytelling ability. And thanks for introducing me to glob. That's such a useful command to know for the future.
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
If it wasn't for your inner developer, this would have been the most boring and useless article ever.
But your inner developer made it way interesting and amazing to read. Hi five to that inner developer.
PS. I am going to put my next article this way. Wish me luck from your inner developer :)
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
I'm a Staff Software Engineer at Cisco. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
I'm a dev with a strong *NIX sysadmin background. I've been programming for 20+ years, started with IRC scripts, C, Python, PHP, Ruby/Rails, Node/JS, Go and Elxir. Full time on Ruby,Elixir and Rust.
Syntax is important for expressiveness. I love both Python and Ruby for their own strengths. In this case && IMHO, Ruby wins with its one-line that mostly reads like plain english.
We're a place where coders share, stay up-to-date and grow their careers.
I hope you never face layoffs 😱🤞
We’ve got a pretty stable business model, as long as I keep bringing in new knowledge and practice. 😃
Here's one way of doing this using the standard Linux utils
Explanation:
source <(CMD)executes text output ofCMDas a command.find . -type f -name "*.1"finds all files in current directory ending with.1sed -nr "s/(^.*)\.(.*)\.1/mv \1.\2.1 \1.\2/p"uses a regex to get the basename and extension before.1and outputs a move command with.1removed.sourceWe can also use
execoption 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
awkinstead ofsourceas follows:This makes the
evalof strings part of the pipeline.I once faced a similar issue. My boss, who isn't an IT guy at all, wanted to change the extension of many files. He told me to do it (for I was the new hire then). All the files had a common extension. I did not have to write a code to automate it, I just opened cmd and used the command (rename *.zip *.xlsx)
that's it!
As I was reading through your post, this solution kept popping up in my mind. But then I realized that you had different extensions to change.
Yeah, it would have been a lot easier if I hadn't needed to preserve some amount of the original extension. But definitely a PowerShell one-liner was my first thought.
Python is such an awesome glue/hack language. I love your storytelling ability. And thanks for introducing me to glob. That's such a useful command to know for the future.
Thanks! Glad you liked it!
Ahah nice story 🤣
If it wasn't for your inner developer, this would have been the most boring and useless article ever.
But your inner developer made it way interesting and amazing to read. Hi five to that inner developer.
PS. I am going to put my next article this way. Wish me luck from your inner developer :)
Um. Thank you, I think?
Thanks for sharing this. I love these little scripts that do awesome, little tasks so well.
Glad you liked it!
Syntax is important for expressiveness. I love both Python and Ruby for their own strengths. In this case && IMHO, Ruby wins with its one-line that mostly reads like plain english.