Showing posts with label Linux File Copy. Show all posts
Showing posts with label Linux File Copy. Show all posts

Tuesday, December 11, 2012

Bash One Liner: copy template_*.txt to foo_*.txt

Say I have three files (template_*.txt):
  • template_x.txt
  • template_y.txt
  • template_z.txt
I want to copy them to three new files (foo_*.txt).
  • foo_x.txt
  • foo_y.txt
  • foo_z.txt
for f in template_*.txt; do cp $f foo_${f#template_}; done
or
for file in template_*.txt ; do 
  cp $file `echo $file | sed 's/template_\(.*\)/foo_\1/'` ;  
done