![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to List and copy the files containing a string | redlotus72 | UNIX for Dummies Questions & Answers | 11 | 09-28-2007 11:58 AM |
| script to rename files with current date and copy it. | logic0 | UNIX for Dummies Questions & Answers | 6 | 05-01-2007 05:13 AM |
| rename files | mpang_ | Shell Programming and Scripting | 2 | 11-01-2006 01:17 PM |
| please help - script to list and rename | happyv | Shell Programming and Scripting | 2 | 10-04-2006 03:50 AM |
| Mass Copy/rename | lwilsonFG | UNIX for Dummies Questions & Answers | 6 | 11-03-2005 06:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hi all,
I am a newbie in writng unix..I am using ksh shell..Does anyone know how to copy a list o files from directory A to directory B with differnt names? i.e in Dir A, I have RPT101.555.TXT RPT102.666.TXT and I want to copy those files to dir B with new naming convention.. in Dir B, I wanna have those files names RPT.101.555.20050225163012.TXT RPT.102.666.20050225163013.TXT ... where 20050225163012 is infact the timestamp when I copy those files format is yyyymmddHHmmss I try to use comand sed ..but I am in big mess right now.. please help.. Thx~! |
|
|||||
|
Here's one that'll work regardless of which input filename format (RPT101.*.TXT or RPT.101.*.TXT) is used....
Code:
$ cd /dirA
$ ls -1 *.TXT
RPT.102.666.TXT
RPT101.555.TXT
$ cat > rename.ksh
#!/bin/ksh
ls *.TXT | while read file
do
cp "$file" /dirB/${file%.*}.`date '+%Y%m%d%H%M%S'`.TXT
done
^D
$ chmod +x ./rename.ksh
$ ./rename.ksh
$ ls -1 /dirB/*.TXT
RPT.102.666.20050226024347.TXT
RPT101.555.20050226024347.TXT
ZB |
|
||||
|
Thx for all reply first. To be more specific, this is my data..
SSSBR101R01A123.D20041224.TXT I want to copy this file to another directory with a new name SSSBR101.R01.A123.RPTDUMMY.D20041224.20040226.183033.BIN |________| This is the current date and time yyyymmdd.HHmmss ========================= converning the solution given above.. I try the follwing and put the news files in teh same dir after renaming and simpfy the rename convention..but I got this error when I try to run the script.. [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: ls SFSBR101R01I123.D20050131.TXT SFSBR101R01ITLS.D20050131.TXT SFSBR101R01IABF.D20050131.TXT rename.ksh [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: ls SFSBR101R01I123.D20050131.TXT SFSBR101R01ITLS.D20050131.TXT SFSBR101R01IABF.D20050131.TXT rename.ksh [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: cat rename.ksh #! /bin/sh ls *.TXT | while read file do cp "$file" ${file%.*}.`date '+%Y%m%d%H%M%S'`.TXT done ^D[devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: ls -l rename.ksh -rwxr-xr-x 1 devuser dba 106 Feb 26 11:24 rename.ksh [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: rename.ksh ksh: rename.ksh: not found [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: why? |
|
|||||
|
Quote:
./rename.ksh Cheers ZB |
|
||||
|
ZB,
thx for yr reply but same problem even I re-run it like following, [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: ls SFSBR101R01I123.D20050131.TXT SFSBR101R01ITLS.D20050131.TXT SFSBR101R01IABF.D20050131.TXT rename.ksh [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: ./rename.ksh ksh: ./rename.ksh: not found [devuser]/project/sfs/ostdev/ftp/snd/ondemand/rpt_txt: |
|
|||||
|
For a start, make sure that you change the shebang line to
#!/bin/ksh as there are korn shell specific builtins used.... Also, remove the ^D from the end of the script - that was in my output because I scripted on the fly redirecting cat to a file.... Try doing ls -lb . to check that no non-printing characters have been put into the rename.ksh filename as you entered it in.... if you see some octals in there - that's the culprit.... Let us know if that makes any difference. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|