Rename scripts using xargs/sed | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    

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 !!

Rename scripts using xargs/sed

UNIX for Dummies Questions & Answers

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 02-12-2013
Grueben Grueben is offline
Registered User
Join Date: Aug 2010
Last Activity: 29 December 2014, 4:38 AM EST
Posts: 90
Thanks: 47
Thanked 0 Times in 0 Posts
Rename scripts using xargs/sed

Morning all

I've got loads of scripts but the names are too long! I've stuck the list in a flat file (names) and I'm trying to read that in line by line and create the new names (in to directory new) from the list. It looks like this:

 xargs -n1 -I{} <names cat {} | sed 's/scr99000001/scr991/g' >new

I can't get it to write the new files out seperately. It just plows them all into one file.

Any help much appreciated

PS - I also suspect if it does work it will just replace 99000001 with 99100001 !

Last edited by joeyg; 02-12-2013 at 07:39 AM.. Reason: Please wrap commands and data within CodeTags
Sponsored Links
Old 02-12-2013
alister alister is offline
Registered User
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 973 Times in 789 Posts
You can just read the filenames from your file using a while-read loop. Within that loop, use cp. To generate the destination filename, you can use sed or the shell's parameter expansion operators to strip leading directories, modify the filename (e.g. ${var//pattern/replacement}), and prepend the new directory.

Alternatively, you can use pax in copy mode, -rw, with the -s option to modify the filenames as they're copied to the destination.


Last edited by alister; 02-12-2013 at 09:51 AM..
The Following User Says Thank You to alister For This Useful Post:
Grueben (03-14-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed file rename jennyjones Shell Programming and Scripting 2 06-15-2012 06:58 AM
Rename file using sed or awk sandy88 Shell Programming and Scripting 14 06-07-2012 09:57 AM
try to batch rename using sed (if this is best) johnstrong Shell Programming and Scripting 3 02-09-2011 12:44 PM
Rename file using sed command fanny_tirtasari Shell Programming and Scripting 20 04-28-2010 09:04 AM
Multiple rename part of scripts waso Shell Programming and Scripting 2 11-19-2009 06:13 AM

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