• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 737
  • Last Modified:

Mac Terminal or Automater command to remove file extension from files in folder

Hi Experts

I am on a Mac Computer.  I have a folder with a lot of text files with an extension of:  .txt.imp

Is there a terminal command or a method on how I can quickly remove the .imp    and/or  remove the .txt.imp  from the tail end of the file?

Example
Please do not suggest me to download any software.  I would like a command, script, or automater action to do this.  Thanks!  (Preferably a terminal command would be awesome).
0
activematx
Asked:
activematx
  • 3
  • 2
  • 2
1 Solution
 
omarfaridCommented:
you can run command like

rm *.txt.imp

OR

rm *.imp

You need to be careful since these files will be removed and can't be recovered.
0
 
goubunCommented:
You also can run

rm -rf *.txt.imp

to remove the files without prompting for confirmation, it's so useful when there are a lot of files
0
 
activematxAuthor Commented:
I am sorry, let me clarify.  I am trying to rename the files and not remove them.  I would like to rename them by removing the extension(s).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
goubunCommented:
You can use this

find . -iname "*.txt.imp" -exec bash -c 'mv "$0" "${0%\.txt.imp}"' {} \;

to remove the extension of all files that end with txt.imp, if you need remove the extension txt.imp and add another extension like .php you can use

find . -iname "*.txt.imp" -exec bash -c 'mv "$0" "${0%\.txt.imp}.php"' {} \;
0
 
omarfaridCommented:
you can run

for file in *.txt.imp
  do
    f=`awk -F'.' '{ print $1 }'`
    mv $file $f
done
0
 
activematxAuthor Commented:
Thanks, you got me on the right track.  I ended up using:

for f in *.txt.imp; do
  mv "$f" "${f%.*}"
done

Any idea on why yours would not quit in the terminal.  (would not proccess done)
0
 
omarfaridCommented:
Ok, I missed this:

  f=`awk -F'.' '{ print $1 }'`

It should be

  f=`echo $file | awk -F'.' '{ print $1 }'`
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now