![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 multiple files | jayell | Shell Programming and Scripting | 7 | 01-12-2009 04:27 PM |
| Renaming multiple files | Jazmania | Shell Programming and Scripting | 6 | 01-02-2009 02:16 PM |
| Renaming Multiple files | dhiren_shah | UNIX for Dummies Questions & Answers | 2 | 09-12-2008 01:23 AM |
| Renaming multiple files | rmayur | UNIX for Dummies Questions & Answers | 6 | 02-26-2004 04:40 AM |
| Renaming multiple files | jxh461 | Shell Programming and Scripting | 4 | 04-01-2003 06:25 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Renaming Files (Multiple files)
Hi,
I have a directory with files names like ABC20090101AXY.txt, ABC20090102BZ.txt,ABC20090101COF.txt etc. The digits in the filenames represent the date. I want to rename the files to AXY.txt, BZ.txt and COF.txt I tried with this code. myfile= date '+ABC%Y%m%d' for i in *.txt do mv $i `echo $i | sed 's/$myfile//'` done But its giving message mv: ABC20090101AXY.txt and ABC20090101AXY.txt are identical Can u help me finding the problem. Regards, Shekhar |
|
||||
|
Hi,
shell variables inside '' are not expanded. So here Code:
mv $i `echo $i | sed 's/$myfile//'` Either use "..." or no sed at all. Shell built-ins are enough. Try: Code:
mv $i ${i/200[7-9][0-1][0-9][0-3][0-9]/}
|
|
||||
|
Try this
myfile=$(date '+ABC%Y%m%d') for i in *.txt do mv $i `echo $i | sed "s/$myfile//"` done i thik u didnt use back tics or $() to set variable myfile. to expend $myfile use " instead of ' i tried this a=$(date '+ABC%Y%m%d') echo ABC20090103AXY.txt | sed 's/$a//g' ABC20090103AXY.txt echo ABC20090103AXY.txt | sed "s/$a//g" AXY.txt echo '$aABC20090103AXY.txt' | sed "s/$a//g" $aAXY.txt echo '$aABC20090103AXY.txt' | sed 's/$a//g' ABC20090103AXY.txt |
|
||||
|
Quote:
Code:
# ls -1 ABC20090101AXY.txt ABC20090101COF.txt ABC20090102BZ.txt # filerenamer.py -p "ABC\d+" -e "" -l "ABC*.txt" ==>>>> [ /home/ABC20090101COF.txt ]==>[ /home/COF.txt ] ==>>>> [ /home/ABC20090101AXY.txt ]==>[ /home/AXY.txt ] ==>>>> [ /home/ABC20090102BZ.txt ]==>[ /home/BZ.txt ] |
|
||||
|
Quote:
Code:
awk '{ system("mv " FILENAME" " substr(FILENAME,1,12) )}' ABC*.txt
|
| Sponsored Links | ||
|
|