![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Script to rename files | cpreovol | Shell Programming and Scripting | 3 | 04-01-2008 08:45 AM |
| rename a lot of files again | ajp7701 | Shell Programming and Scripting | 11 | 03-31-2008 04:36 PM |
| script to rename files with current date and copy it. | logic0 | UNIX for Dummies Questions & Answers | 6 | 05-01-2007 02:13 AM |
| Rename Files with a script ? | yoveln | OS X (Apple) | 1 | 02-08-2004 08:45 AM |
| How to rename files? | CompuTelSystem | UNIX for Dummies Questions & Answers | 9 | 05-14-2002 12:28 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Script to rename files
Have files of the sort 3p1522015.dgn and need to have them renamed to 152201.dgn. Essentially dropping the 1st 2 characters and the last. I'm relatively new to UNIX and uncertain of where to start. I hope this provides enough detail.
Thanks |
| Forum Sponsor | ||
|
|
|
|||
|
try this ..
if your filenames are of fixed length and you just need to remove the first two chars and last char and rename it , then this might help,
team$ filename="3p1522015.dgn" team$ basename $filename 3p1522015.dgn team$ basename $filename | cut -c 3-8 152201 team$ newfilename=`basename $filename | cut -c 3-8`.dgn team$ echo $newfilename 152201.dgn team$ unset filename newfilename team$ |
|
|||
|
Yes, this is bash syntax. It takes characters 2 through 6 of filename, appends ".dgn" and assigns it to newfilename. Google for bash regular expressions and you wish find a number of tutorials on the subject.
|
|
|||
|
it is worthy to learn such features of bash, at some situation bash can perform some operation very easily and efficiently compare to sed and awk.specially when you write a bash script you would prefer to use a bash inbuilt command than invoking some other tool or command
Rakesh UV |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|