Cover photo by Tim Easley on Unsplash.
This is just a quick post about something that happened to me yesterday at work.
So there I was: working h...
For further actions, you may consider blocking this person and/or reporting abuse
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 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.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.