LinuxQuestions.org
Help answer threads with 0 replies.
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 10-31-2007, 04:48 PM   #1
mike_stlouis
LQ Newbie
 
Registered: Oct 2007
Posts: 6

Rep: Reputation: 0
renaming file extensions


i understand WHY this will not work, and i see many scripts on-line that do ALMOST the same thing, but not quite....
i want to rename all the files with exentsion: .bas-new to simply: .bas
how can i do that.
# called like: ./rename_script.sh *.bas-new
#!/bin/bash

for filename in "$@";
do
rename *.bas-new *.bas
done
 
Old 10-31-2007, 05:22 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Part of the Pleasure of Linux is the challange. So here's the challenge. Study the use of grep and sed, and their use in a bash script.

Then, in your sudo code, change
Quote:
do
rename *.bas-new *.bas
done
to
Quote:
do
grep bas.new # to select only those lines with the regular expression bas.new
sed -e <substitute /bas.new/bas/g> # to change bas.new to bas
done

Last edited by bigrigdriver; 10-31-2007 at 05:23 PM.
 
Old 10-31-2007, 05:28 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Have a look at the man page for rename (if your distro provides it). You could do something like:
Code:
rename 'bas-new' 'bas' *bas-new
 
  


Reply


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
Renaming multipe files without extensions DIMonS Programming 3 08-09-2007 11:29 AM
renaming extensions christina_rules Linux - Newbie 6 05-23-2006 09:04 AM
bash help, renaming file extensions trey85stang Linux - General 8 07-21-2005 04:51 PM
renaming a file?? U-Toast Linux - Newbie 2 08-29-2004 01:07 AM
renaming or converting a text file to a dat file... tangaz Linux - Software 1 10-24-2003 06:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:38 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration