LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-21-2012, 05:39 PM   #1
Pampano
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Rep: Reputation: Disabled
Question Help with UNIX Shell Scripts


What if I had many files but needed to change the extensions of them and they all have different extensions.

For example, I need an sed command to change the file "batman.CPP" to be "batman.cpp"

And I also have a file "kingsandqueens.dat" and I need it to be "kingsandqueens.backup"


I need a shell script that will do this for me if I were to execute the program as ./chExt1.sh 'cpp' 'batman.CPP'
or ./chExt1.sh 'backup' 'kingsandqueens.dat'

Thanks for any help with this.
 
Old 04-21-2012, 05:43 PM   #2
descendant_command
Member
 
Registered: Mar 2012
Posts: 741

Rep: Reputation: 156Reputation: 156
Maybe you should have paid attention in the class this homework is for ...
 
Old 04-21-2012, 05:49 PM   #3
Pampano
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
I did pay attention. This is the last assignment. I didn't ask for the answer, just "any help" because I am struggling with how to get started.
 
Old 04-21-2012, 06:39 PM   #4
John VV
Guru
 
Registered: Aug 2005
Posts: 12,602

Rep: Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677
post what you have so far

also for changing CAP to lower case there are small shell scripts already posted all over the net
almost EVERY tutorial site would have something
a simple " for i in *; do mv "$i"........... "

Last edited by John VV; 04-21-2012 at 06:42 PM.
 
Old 04-21-2012, 07:42 PM   #5
Pampano
LQ Newbie
 
Registered: Apr 2012
Posts: 5

Original Poster
Rep: Reputation: Disabled
I just need an sed command that rewrites a file to a different file extension
 
Old 04-21-2012, 10:01 PM   #6
John VV
Guru
 
Registered: Aug 2005
Posts: 12,602

Rep: Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677Reputation: 1677
Quote:
I just need an sed command that rewrites a file to a different file extension
and you have been asked twice to post what you have so far
 
Old 04-21-2012, 11:46 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,813

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
man sed
 
Old 04-22-2012, 03:17 AM   #8
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
Not sure why you would use sed at all. As suggested a simple loop and the mv command would be enough or if your distro has it have a look for the rename command.
 
  


Reply

Tags
linux, script, shell, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
LXer: Using Traps Outside Of Shell Scripts On Unix Or Linux LXer Syndicated Linux News 0 07-09-2008 07:41 AM
LXer: Tput: Add some spice to your UNIX shell scripts LXer Syndicated Linux News 0 04-12-2008 04:50 AM
How to run pl/sql from Unix shell scripts? plz us_chauhan Linux - Server 2 05-15-2007 10:35 AM
Unix scripts to interact with Windows NT ann124 Solaris / OpenSolaris 1 11-09-2004 04:55 PM


All times are GMT -5. The time now is 02:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration