Link to home
Start Free TrialLog in
Avatar of AlexF777
AlexF777

asked on

looking for shell to rename all files like ?????.dlm.???????.????.pip into ?????.dlm.pip.???????.????

Thanks in advance,
-Al
Avatar of shivsa
shivsa
Flag of United States of America image

for i in `ls ??????.dlm.???????.????.pip`
do
   mv $i ?????.dlm.pip.???????.????
done


i am assuming that instaed of ? u have some charecter there.
Avatar of glassd
glassd

I haven't tested this, so buyer beware.

$(ls ?????.dlm.???????.????.pip | awk '{
printf("mv %s %s%s%s\n",$0,substr($0,1,10),"pip",substr($0,10,13))
}')

the awk statement should print out three space separated fields for each line of input.
Field 1 is the string "mv" (the rename command).
Field 2 is the original filename (the whole line).
Field 3 is made up of the first 10 characters of the input file name (?????.dlm.), the string "pip", then the string starting with the 10th character of the filename, 13 characters long (.???????.????).

The input to the awk command is a list of all files of the required format (?????.dlm.???????.????.pip).

Finally, wrapping the whole lot in $(...) causes the shell (ksh or bash) to execute the output rather than just listing it to STDOUT.

Hope it works.
ASKER CERTIFIED SOLUTION
Avatar of yuzh
yuzh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial