![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| renaming xls file | systemsb | UNIX for Dummies Questions & Answers | 2 | 10-19-2007 08:50 AM |
| Renaming a file with spaces | patwa | UNIX for Dummies Questions & Answers | 2 | 06-21-2007 07:50 PM |
| Help in renaming file !!! | kumarsaravana_s | UNIX for Dummies Questions & Answers | 5 | 05-02-2007 01:45 PM |
| Renaming a file name | dbrundrett | Shell Programming and Scripting | 2 | 01-06-2004 10:36 AM |
| Renaming a file to the same name | lachino8 | UNIX for Dummies Questions & Answers | 3 | 07-31-2002 09:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
If you have the file name in $filename you can do the following. Code:
head1=${filename%_[0-9]}
tail=${filename#$head1}
head2=${head1%.*}
ext=${head1#$head2}
mv "$filename" "${head2%$ext}$tail$ext"
This assumes the final suffix is a single digit. The construct ${var#pat} means the value of $var with any match on the pattern pat removed from the beginning; ${var%pat} does the corresponding substitution on the end of the value. See the manual page for your shell for more information. |
|
||||
|
if you have Python , you can download this script. example usage for same file name structure: Code:
# ls -1 re* remark_mm.rmr_19 remark_mm.rmr_3 report_12.rp_1 # filerenamer.py -p "(.*_.*)(\..*)(_.*)$" -e "\\1\\3\\2" -l "re*_*" #remove -l to commit ==>>>> [ /home/remark_mm.rmr_3 ]==>[ /home/remark_mm_3.rmr ] ==>>>> [ /home/remark_mm.rmr_19 ]==>[ /home/remark_mm_19.rmr ] ==>>>> [ /home/report_12.rp_1 ]==>[ /home/report_12_1.rp ] # ls -1 re* remark_mm_19.rmr remark_mm_3.rmr report_12_1.rp |
![]() |
| Bookmarks |
| Tags |
| python, rename files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|