Solved

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

Posted on 2003-12-04
4
418 Views
Last Modified: 2010-04-21
Thanks in advance,
-Al
0
Comment
Question by:AlexF777
  • 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 200 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 50 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now