0

I have few files namely - "a.mov-, attachment", "b.mov-, attachment", "c.mov-, attachment",etc.. I want to trim the keyword: "-, attachment" from all files in that folder.

Please suggest me an approach which script will be best suited for this - AppleScript, Shell, Python etc. (I being a non-scripting guy).

Note: I m using MacOSX-Maverics[Terminal].

aksani56
  • 105

2 Answers2

0

you can use rename command if you're using linux:

rename 's/-, attachment//' *attachment

with a GUI, there is a lot of tools like ANT Renamer for example.

pataluc
  • 620
  • 3
  • 12
0

Using just the shell:

for f in *", attachment"; do
    mv "$f" "${f%, attachment}"
done

The form ${f%something} returns the value of the variable f with the text following the % removed from the end of the value.

$ var="hello world"
$ echo "${var%orld}"
hello w

If you put a glob pattern in there, the shortest match will be removed with ${var%pattern} and the longest match with ${var%%pattern}

$ echo "${var%l*}"
hello wor
$ echo "${var%%l*}"
he

If the pattern does not match the end of the string, nothing is removed

$ echo "${var%foo}"
hello world

See http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion

glenn jackman
  • 27,524