Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-12-2013
Grueben Grueben is offline
Registered User
 
Join Date: Aug 2010
Last Activity: 18 March 2015, 8:26 AM EDT
Posts: 96
Thanks: 50
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:


Code:
 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 06:39 AM.. Reason: Please wrap commands and data within CodeTags
Sponsored Links
    #2  
Old Unix and Linux 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 974 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.

Regards,
Alister

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 05:58 AM
Rename file using sed or awk sandy88 Shell Programming and Scripting 14 06-07-2012 08:57 AM
try to batch rename using sed (if this is best) johnstrong Shell Programming and Scripting 3 02-09-2011 11:44 AM
Rename file using sed command fanny_tirtasari Shell Programming and Scripting 20 04-28-2010 08:04 AM
Multiple rename part of scripts waso Shell Programming and Scripting 2 11-19-2009 05:13 AM



All times are GMT -4. The time now is 01:00 AM.