Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Rename files in bash via string handling' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Rename files in bash via string handling
Authored by: riceran on Sep 07, '06 08:54:27AM
Another approach to this problem is the use of the 'rename' perl script (available at http://www.greenfly.org/rename). With this script, you can simply use a perl regex to systematically rename files. I find it quite handy!

rename 's/TS_(\d+)_.*/Total Entry #$1.txt/' TS*

[ Reply to This | # ]
Rename files in bash via string handling
Authored by: i5ao on Sep 07, '06 10:24:53AM
the hint above replaces by string character position, but you can also use simple pattern matching using slashes: ${variable_name/find/replace}
for f in abc-1.txt abc-2.txt abc-33.txt
do
  echo ${f/abc-/new name -> def_}
done

new name -> def_1.txt
new name -> def_2.txt
new name -> def_33.txt


[ Reply to This | # ]