The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
now to rename multiple files aoussenko Shell Programming and Scripting 4 06-11-2008 07:46 PM
rename multiple files antointoronto Shell Programming and Scripting 13 03-20-2008 10:16 AM
Rename part of multiple files sajjad02 Shell Programming and Scripting 4 02-22-2005 01:30 PM
Rename multiple files luiz_fer10 UNIX for Dummies Questions & Answers 7 06-11-2002 09:06 AM
Rename Multiple Files molonede UNIX for Dummies Questions & Answers 1 11-14-2000 12:40 PM

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 12-24-2008
woodstock woodstock is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 5
rename multiple files from search output

Variations of multiple renames seems to come up a lot but i can't find the answer to this situation.
Tidying up a directory where people rename files to .working, .bob, .attempt1 & so on.

what i am trying to do is: list the file type, & rename from ".whatever" to .fixed.
As the ".whatever" is rarely the same, it makes this a bit more than the normal rename all ".a's" to ".b's" if you get my drift.

For this particular list of example files i have come up with:

for i in `ls WLAN_* | egrep -v 'TRF|fixed' | cut -d "." -f1`;do mv $i.* $i.fixed;done

which appears to work fine but a tad "around the houses". I was hoping someone knew a better way/shorter command string.
Example files as follows:

1.sh
bla1.txt
bla2.csv
WLAN_20081128_00051453_01.TRF
WLAN_20081128_00051468_01.TRF
WLAN_20081128_00051469_01.TRF
WLAN_20081128_00051470_01.TRF
WLAN_clo_20081202_00051984_01.sg-working2
WLAN_clo_20081129_00051540_01.sg-working
WLAN_clo_20081129_00051580_01.sg-working
WLAN_clo_20081202_00052011_01.still_failed
WLAN_clo_20080923_00043115.done
WLAN_20081128_00051467_01.TRF
WLAN_20081128_00051466_01.TRF
WLAN_20081128_00051465_01.TRF
WLAN_20081128_00051454_01.TRF
WLAN_20081128_00051455_01.TRF
WLAN_20081128_00051456_01.TRF
WLAN_20081128_00051457_01.TRF
WLAN_20081128_00051458_01.TRF
WLAN_20081128_00051459_01.TRF
WLAN_20081128_00051460_01.TRF
WLAN_20081128_00051461_01.fixed
WLAN_20081128_00051462_01.fixed
WLAN_20081128_00051463_01.TRF
WLAN_20081128_00051464_01.TRF
WLAN_clo_20081222_00054519_01.test1-sg

Desired output ( but this was using my command as above)

1.sh
bla1.txt
bla2.csv
WLAN_20081128_00051453_01.TRF
WLAN_20081128_00051468_01.TRF
WLAN_20081128_00051469_01.TRF
WLAN_20081128_00051470_01.TRF
WLAN_clo_20081202_00052011_01.fixed
WLAN_clo_20081129_00051580_01.fixed
WLAN_clo_20081202_00051984_01.fixed
WLAN_clo_20081222_00054519_01.fixed
WLAN_clo_20080923_00043115.fixed
WLAN_20081128_00051467_01.TRF
WLAN_20081128_00051466_01.TRF
WLAN_20081128_00051465_01.TRF
WLAN_20081128_00051454_01.TRF
WLAN_20081128_00051455_01.TRF
WLAN_20081128_00051456_01.TRF
WLAN_20081128_00051457_01.TRF
WLAN_20081128_00051458_01.TRF
WLAN_20081128_00051459_01.TRF
WLAN_20081128_00051460_01.TRF
WLAN_20081128_00051461_01.fixed
WLAN_20081128_00051462_01.fixed
WLAN_20081128_00051463_01.TRF
WLAN_20081128_00051464_01.TRF
WLAN_clo_20081129_00051540_01.fixed

  #2 (permalink)  
Old 12-24-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
You can do something along the lines of :

Code:
ls WLAN_* | egrep -v 'TRF|fixed|.txt|.csv|.sh' | 
   while read file
      do 
         mv "$file" "${file%.*}".fixed
      done
Modify it to fit your needs.
  #3 (permalink)  
Old 12-27-2008
woodstock woodstock is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 5
quite like that

Yep! quite like that. saves mucking around with a delimiter.
made a one liner out of it and worked fine.

ls WLAN_* | egrep -v '.fixed|.TRF'| while read file; do mv "$file" "${file%.*}".fixed; done

still quite long though. Just me being lazy i suppose. I like your use of the while loop.
  #4 (permalink)  
Old 12-27-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,869
With Perl:

Code:
perl -e'
  map {($n = $_) =~ s/[^.]+$/fixed/; rename $_, $n}
    grep !/\.(csv|sh|txt|TRF|fixed)$/, glob "*.*"
    '
  #5 (permalink)  
Old 12-28-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Quote:
Originally Posted by rubin View Post
You can do something along the lines of :

Code:
ls WLAN_* ...
Modify it to fit your needs.
Posting back my learnings from here

ls WLAN* is not needed - there is no need for a process to be spawned here just shell construct is sufficient here

Code:
for file_name in WLAN_*
How to select the *.txt files using Loops

Thanks to cfajohnson !
  #6 (permalink)  
Old 01-06-2009
woodstock woodstock is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 5
Thanks for your suggestions folks. Handy forum. I've not tried perl before but will have a read up. I think for the time being i will stick with the "for i" & "while" methods for this though.
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 11:48 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