[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2013-11-11
7
Medium Priority
?
731 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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 …

649 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