Unix admin here. I need to rename a bunch (thousands) of files on a windows server. As an example, the files need to go from a filename of backup-moodle2-course-33579-wi19_sosc235-01-20190127-2236.mbz to wi19_sosc2352236.mbz. I can accomplish this by moving the files to one of my unix servers and doing the following:
for i in `ls`; do mv $i `ls $i|awk -F ‘-’ '{x=$5$6; print x".mbz"}'`; done
This is not going to be a one time thing, so if I could create a script, or command line the user could run from Powershell on his own that would be great. I’m really new to Powershell (just heard about it today) and have been going through some documentation, but a little confused. So, if anyone has any ideas it would be greatly appreciated. Thanks.
# these aliases were taken out of linux and osx to avoid confusion
# I put them back in my $profile in osx
set-alias ls get-childitem
set-alias mv move-item
foreach ($i in ls) { $s = $i -split '-'; mv $i ($s[4] + $s[7]) -whatif }
foreach ($i in ls) { mv $i (-join ($i -split '-')[4,7]) -whatif }
Here’s a simple demo of something like that awk operation: