Rename multiple files with bash for loop, mv, and sed -
My goal 'img_MM-DD-YY_XX.jpg' to rename the form of files folder 'newyears_YYYY' - MM-DD_XXX.jpg 'by using sed to substitute each file name again and based on character positions. Unfortunately I do not seem to be working on status-based swaps.
For example Here's my attempt (Ignore for _XX part): [0- 9] [0-9] / P> Any ideas how can I fix this? Any sound above the thing and includes locates the first after the date of 6 points. It replaces the initial part with the Two-digit MM, DD or standard value matched with Blackslashes to eliminate some, I used the s /. [4 \} [0-9] [0-9] / Trying to change MM with YY
for file name in images * * new name = $ (echo $ filename | sed / s. {4 \} [0- 9] [0-9] /. \ {10 \} [0-9] [0-9] /; s /. \ {7 \} [0-9] [0-9] /. \ 4 \} [0-9] [0-9] /; s /. \ {10 \} [0-9] [0- 9] /. \ {7 \} [0-9] [0- 9] /; c / Yng_ / Nevyears_20 / ') mv $ filename $ Nunme Done
$ echo 'img_11-22-14_XX.jpg' | Sed -r 's / [^ _] * _ ([0- 9] {2}) - ([0- 9] {2}) - ([0- 9] {2}) / NewIer_20 \ 3- \ 1- \ 2 / 'newyears_2014-11-22_XX.jpg
newyears _ and reproduces the date from 20-yy-mm-dd to mm-dd-yay.
([0-9] {2}) . The parentheses indicate that
sed should capture the value for later use. The output side of the replacement is
_20 \ 3- \ 1- \ 2 . It restores the underlined and adds a
20 to the front of the year. The year was the third occupation value, so it has been marked as
\ 3 . Similarly, months ago was assumed possession, so it is marked
\ 1 and on the second day it is because it is
\ 2 .
-r option to invite extended regular expressions. If you are on Mac or other non-GNU systems, use
sed -r instead of
sed -E . Otherwise, use:
sed 's / [^ _] * _ \ ([0-9] \ {2 \} \) - \ ([0- 9] \ {2 \} \) - \ ([0- 9] \ {2 \} \) / newyears_20 \ 3- \ 1- \ 2 / '
Comments
Post a Comment