2010年12月15日 星期三

[Gentoo]shell script file rename 更名


假設我的資料有

gradshow.asp?gid=101003
gradshow.asp?gid=101004
gradshow.asp?gid=101006
gradshow.asp?gid=102006
gradshow.asp?gid=102013
gradshow.asp?gid=103004
gradshow.asp?gid=103017
gradshow.asp?gid=103020
gradshow.asp?gid=104009
gradshow.asp?gid=107014
gradshow.asp?gid=108002
gradshow.asp?gid=108004
gradshow.asp?gid=110006
gradshow.asp?gid=119002
gradshow.asp?gid=128002
gradshow.asp?gid=129003
gradshow.asp?gid=130002
gradshow.asp?gid=131006

[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ i=gradshow.asp?gid=129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo $i
gradshow.asp?gid=129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp*}

[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp/}
?gid=129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp?gid/}
=129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp?gid=/}
129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp?gid=/gid/}
gid/129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ echo ${i/gradshow.asp?gid=/gid}
gid129003
[pcl99@gais4 ~/data/dblp/reg_aca/rawTest]$ for i in gradshow* ;do mv "$i" "${i/gradshow.asp?gid=/gid}".html ;done
 成功更名 


gid012004.html  gid018021.html  gid042018.html  gid069015.html  gid091009.html
gid012005.html  gid018022.html  gid043006.html  gid070017.html  gid092006.html
gid012006.html  gid019006.html  gid044002.html  gid072004.html  gid093003.html
gid012007.html  gid020013.html  gid044005.html  gid072013.html  gid093009.html 

 

沒有留言:

張貼留言