1

I'm wondering how to make mass rename (using rename or sed/awk), for files like this:

Name 1 - Name 2 - Name 3.doc
Name 1- Name 2 - Name 3.doc
Name 1 -Name 2 - Name 3.doc

the problem is that i want to have all files in the same schema, for example

Name 1-Name 2-Name 3.doc

without spaces at all. I'm reading rename documentation but can't find way to do this.

ProgramFOX
  • 6,131
  • 11
  • 45
  • 51
user1854236
  • 446
  • 1
  • 5
  • 16

2 Answers2

2

How about:

for file in *.doc; do 
   mv "$file" "$(sed 's# *- *#-#g' <<< "$file")"
done
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
  • but it removes all spaces, and i need to remove only spaces before and after '-', is it possible at all by one action? – user1854236 Jun 16 '13 at 23:11
2

Try doing this :

rename 's/\s*-\s*/-/g' *.doc

You need the Perl's rename, see this post

Community
  • 1
  • 1
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • Works fine, thanks man, only one problem is it deletes spaces only before and after first '-', not the second one. cheers! – user1854236 Jun 16 '13 at 23:32