Solved

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

Posted on 2013-11-11
7
695 Views
Last Modified: 2013-11-11
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
Comment
Question by:activematx
  • 3
  • 2
  • 2
7 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 39640757
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
 
LVL 2

Expert Comment

by:goubun
ID: 39640770
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
 
LVL 9

Author Comment

by:activematx
ID: 39640771
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 2

Expert Comment

by:goubun
ID: 39640781
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
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 39640784
you can run

for file in *.txt.imp
  do
    f=`awk -F'.' '{ print $1 }'`
    mv $file $f
done
0
 
LVL 9

Author Closing Comment

by:activematx
ID: 39640800
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 39640847
Ok, I missed this:

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

It should be

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now