Guys, i need to replace a particular pattern in lots of files in a folder with another pattern . Is there any command line script I can use to do the functionality.
Eg:
aalex > ls
green_1234_colour.max
red_1234_pen.max
yellow1234flower.max
Need to replace the 1234 in the file name with 9876 i.e,
aalex > ls
green_9876_colour.max
red_9876_pen.max
yellow9876flower.max
How can i do this??
Alex
$ for i in *1234*.max; do
mv -v "$i" "$(echo $i | sed 's/1234/9876/')"
done
green_1234_colour.max -> green_9876_colour.max
red_1234_pen.max -> red_9876_pen.max
yellow1234flower.max -> yellow9876flower.max
$
Thank u guys for the replay.
I think rename doesn't work for this situation as we need to look for a particular expression and replace it with a new pattern.
Why not ? rename is for renaming right ?! what expression you are thinking of ?
# ls
green_1234_colour.max red_1234_pen.max yellow1234flower.max
# rename 1234 9846 *
# ls
green_9846_colour.max red_9846_pen.max yellow9846flower.max
Sorry dude, i didint think like this..as this pattern comes in between...great..thanks