?
Solved

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

Posted on 2013-11-11
7
Medium Priority
?
727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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 2000 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

764 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