Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

extension changing

Posted on 2006-05-16
4
Medium Priority
?
235 Views
Last Modified: 2010-04-20
hi!i need to write a shell script which changes the extensions of files in a directory.
For example, if the name of the script is ext.sh then a call such as below
ext.sh c cpp
changes the extensions of files which are "c" to "cpp"..

Need your help, thanks..
0
Comment
Question by:btocakci
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 16693767
Hi btocakci,

find . -type f -name "*.$1" | sed "s:\(.*\)\.$1:\1:" | while read filename
do
      mv $filename.$1 $filename.$2
done

Cheers!
Sunnycoder
0
 
LVL 12

Expert Comment

by:Heem14
ID: 16693883
FWIW, you can do this without a script as well


rename .c .cpp *.c

or for another example

rename .txt .text *.txt

0
 

Author Comment

by:btocakci
ID: 16694033
hi sunnycoder!
which variable is c and which one is cpp??
how can adapt your command as i want? (c to cpp)
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 16694056
>ext.sh c cpp
>changes the extensions of files which are "c" to "cpp"..
$1 is the first argument ... c in your example ... $2 is the second argument ... cpp in your example
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 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