Renaming filename with another part of the filename
by iicapn from LinuxQuestions.org on (#59GYG)
I've been trying to find a way to do this, but I googling it is difficult because people want simple string replacements. I'm looking to move parts of a filename around... Let me explain. I have files in directory like this:
01-2015.pdf
01-2016.pdf
01-2017.pdf
01-2018.pdf
02-2015.pdf
02-2016.pdf
02-2017.pdf
02-2018.pdf
...
I want those filenames to be like this:
2015-01.pdf
2016-01.pdf
2017-01.pdf
2018-01.pdf
2015-02.pdf
2016-02.pdf
2017-02.pdf
2018-02.pdf
...
The closest I've come is a blog post (http://www.peteryu.ca/tutorials/shel...n_the_filename)
So I tried something like this:
Code:ls -1 | awk '{print("mv "$1 " " $1)}' | sed 's|d{2}-|-d{4}{$1}|2' > rename.txtBut I'm not quite there...
If anyone could help me, thank you so much!!!


01-2015.pdf
01-2016.pdf
01-2017.pdf
01-2018.pdf
02-2015.pdf
02-2016.pdf
02-2017.pdf
02-2018.pdf
...
I want those filenames to be like this:
2015-01.pdf
2016-01.pdf
2017-01.pdf
2018-01.pdf
2015-02.pdf
2016-02.pdf
2017-02.pdf
2018-02.pdf
...
The closest I've come is a blog post (http://www.peteryu.ca/tutorials/shel...n_the_filename)
So I tried something like this:
Code:ls -1 | awk '{print("mv "$1 " " $1)}' | sed 's|d{2}-|-d{4}{$1}|2' > rename.txtBut I'm not quite there...
If anyone could help me, thank you so much!!!