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 s /. [4 \} [0-9] [0-9] / Trying to change MM with YY

Here's my attempt (Ignore for _XX part): [0- 9] [0-9] / P>

  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   

Any ideas how can I fix this?

$ 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

Any sound above the thing and includes locates the first after the date of 6 points. It replaces the initial part with the newyears _ and reproduces the date from 20-yy-mm-dd to mm-dd-yay.

Two-digit MM, DD or standard value matched with ([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 .

Blackslashes to eliminate some, I used the -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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -