Batch file renaming
I have some files formatted like:
bleh-blehdableh-5605-56052.pdf.jpg The final desired result should be: 5605-56052.jpg Please do you know a oneliner that can do this? Bueller? |
Not a one liner but this should work if run in the directory where the files are:
Code:
for file in $(ls *-*-*-*.pdf.jpg) |
Any script can be made a one liner if you replace all the new lines with ; characters ;)
The are many, many, ways to do it. This one assumes that your bleh-blehdableh is always in lowercase and is designed to be reasonably obvious about what's being done. Code:
for i in *;do mv "${i}" $(echo "${i}" | sed 's/\.pdf\././;s/[a-z]*-[a-z]*-//');done |
Quote:
It did inspire this though: Code:
for i in *;do mv "${i}" $(echo "${i}" | cut -d '-' -f 3,4 | cut -d '.' -f 1,3);done |
I tried your oneliner arizona but no luck:
To be more precize, the name is like: word-word-word-word-digits-smallword-word-5000-50002.jpg I was hoping for some regular expression like cutting the words before the double digits (5000-50002.jpg) Any idea? |
Quote:
This is more flexible in that it replaces any lowercase letters or - characters at the start of the filename. Code:
for i in *;do |
Thanks! With sed I can handle it!
|
[QUOTE=arizonagroovejet;4063376]Looks much cleverer than mine except it doesn't remove the .pdf part. I'm not familiar enough with awk to amend it so it does.
I forgot about removing the pdf part. Just piping to an additional awk would do it: Code:
for file in $(ls *-*-*-*.pdf.jpg) Code:
for file in $(ls *-*-*-*.pdf.jpg) |
You might try this:
Code:
find -type -maxdepth 1 -iname '*.jpg' | sed 's@.*\([[:digit:]]\{4\}-[[:digit:]]\{5\}\).*@& \1.jpg@' | xargs echo mv The Perl version of the rename command may also make it simpler but it's not available in all systems. |
Quote:
use shell expansion instead of ls. Code:
for file in *-*-*-*.pdf.jpg |
Well I am not sure if you are running from within the directory or elsewhere, but I am going to assume the first:
Code:
for f in *.jpg |
Quote:
|
Quote:
|
Quote:
|
All times are GMT -5. The time now is 07:44 PM. |