Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-12-04
4
Medium Priority
?
439 Views
Last Modified: 2010-04-21
Thanks in advance,
-Al
0
Comment
Question by:AlexF777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9877914
for i in `ls ??????.dlm.???????.????.pip`
do
   mv $i ?????.dlm.pip.???????.????
done


i am assuming that instaed of ? u have some charecter there.
0
 
LVL 7

Expert Comment

by:glassd
ID: 9878488
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.
0
 
LVL 38

Accepted Solution

by:
yuzh earned 800 total points
ID: 9880474
This following little script should do the job for you:

#!/bin/ksh

for i in `ls ??????.dlm.???????.????.pip`
    N1=`echo $i | cut -d "." -f 1`
    N2=`echo $i | cut -d "." -f 3`
    N3=`echo $i | cut -d "." -f 4`
    mv ${i} ${N1}.dlm.pip.${N2}.${N3}
done

echo "Job done, thanks !"
exit

#   END OF SCRIPT



0
 
LVL 7

Assisted Solution

by:glassd
glassd earned 200 total points
ID: 9880568
Yes yuzh, using the period as the separator was so obvious that I missed it completely.

$(ls ?????.dlm.???????.????.pip | awk -F"."'{
printf("mv %s %s.%s.%s.%s.%s\n",$0,$1,$2,$5,$4,$3)
}')
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question