Register
It is currently Fri Oct 31, 2014 8:40 pm

Rename files with some conditions


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Tue May 18, 2010 7:59 am   

Joined: Tue May 18, 2010 7:08 am
Posts: 5
Hi, I am seeking for a script which rename the pdf files only using the last 16 characters of file name
example
AAS030510SE---0029610.pdf rename as SE---0029610.pdf
RM030510LL---0509710.pdf renmae as LL---0509710.pdf

However, I have created Script as below

for i in *.pdf
do
src=$i
ct=$(echo $i | wc -c)
case $ct in
17) tgt=$(echo $i | cut -c 1-17)
;;
23) tgt=$(echo $i | cut -c 7-23)
;;
25) tgt=$(echo $i | cut -c 9-25)
;;
26) tgt=$(echo $i | cut -c 10-26)
;;
esac
mv -v $src $tgt >> info_rena
done

but, I would like to appreciate solution to pick up last 16 characters of file name from back.

Thanks :)


Top
 Profile  
 PostPosted: Tue May 18, 2010 3:36 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 552
for example:
Code:
var=foobarbaz
echo ${var:$((${#var}-6))}
barbaz


Top
 Profile  
 PostPosted: Tue May 18, 2010 4:37 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Code:
a='alsdfjlkasjfkja;slkfj;lkasj;lkfjdsazxlckv'01234567890123456
echo ${a: -16} # 1234567890123456
a=123
echo ${a:-16} # 123


Top
 Profile  
 PostPosted: Tue May 18, 2010 4:42 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 552
yes !


Top
 Profile  
 PostPosted: Wed May 19, 2010 3:15 am   

Joined: Tue May 18, 2010 7:08 am
Posts: 5
Thank you very much for help..... :)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP