The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - Counting number of similar lines dhanamurthy Shell Programming and Scripting 8 05-16-2008 07:00 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Searching filenames containing certain text??? skyineyes UNIX for Advanced & Expert Users 6 01-16-2008 07:48 AM
Removing certain text from multiple filenames Djaunl UNIX for Dummies Questions & Answers 6 01-15-2008 05:52 PM
changing filenames in a directory to a number within a loop visitorQ Shell Programming and Scripting 30 12-14-2007 01:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2007
Djaunl Djaunl is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 13
Appending text to a number of similar filenames

Hi,

I was wondering if there was a way to append something to filenames based on a wildcard. For example, if I have the following files in a directory:

blah1
blah2
blah3
blah4
blah5

I want to rename these all to:

blah1.txt
blah2.txt
blah3.txt
blah4.txt
blah5.txt

Is there a way to select all the blah files (using say, 'blah*'?) and then appending the same text to the end of them? I was looking at the mv command, but I was unsure of how to take all the filenames after saying 'mv blah*' and append text to them.

Thanks,
Dan
  #2 (permalink)  
Old 10-09-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,240

Code:
for file in blah* ; do
    mv $file ${file}.txt
done

  #3 (permalink)  
Old 10-09-2007
Djaunl Djaunl is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 13
Wow, I never even thought of using a loop. That works perfectly!

Just one more quick question:

Is there a similar method that will allow me to remove certain text from a number of files? For example, let's say I want to remove the .txt from all the files.

I apologize if this should easily follow from the above example, but I'm pretty new to this type of manipulation.

Thanks a lot,
Dan
  #4 (permalink)  
Old 10-09-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,240
You could use this in combination with the previous technique.

Code:
# file=abcdef.txt
# echo ${file%%.txt}
abcdef

or use the basename command


Code:
# basename $file .txt
abcdef

  #5 (permalink)  
Old 10-10-2007
Djaunl Djaunl is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 13
Awesome! Thanks so much for the help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0