|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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' >newI 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
|
|||
|
|||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 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 |
|
|