Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy ????.ABC ????BCD

SOLVED
Go to solution
Vernon Brown_4
Trusted Contributor

Copy ????.ABC ????BCD

I'm looking for a shell script that will duplicate the Windows DOS bulk copy command, the title of this thread.

Anyone have one handy ??
8 REPLIES
Steven E. Protter
Exalted Contributor
Solution

Re: Copy ????.ABC ????BCD

Shalom Vernon,

ls -1 ????.ABC > list

while read -r filename
do
cp $filename ????BCD
done < list

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Ross Minkov
Esteemed Contributor

Re: Copy ????.ABC ????BCD

For tasks like this I use the famous rename perl script (written by Larry Wall iirc). The rename script is (I hope this pastes ok):

#!/usr/bin/perl
#
# use shift to extract the first command line argument - this is the string
# containing the Perl statement(s) to be compiled and executed.
# These Perl operations are stored in a $op variable.

($op = shift) || die "Usage: rename expr [files]\n";

chomp(@ARGV = ) unless @ARGV;

foreach (@ARGV) {
# save the current file name in $was
$was = $_; # $_ is the default loop variable
eval $op; # compile and execute the Perl
# operations submitted by the user
die if $@; # means eval 'failed'
rename($was, $_) unless $was eq $_; # rename is a Perl built-in function
}



Then you use it like this:

rename 's/\.ABC$/BCD/' *.ABC

or maybe you meant:

rename.pl 's/\.ABC$/\.BCD/' *.ABC


HTH,
Ross
Vernon Brown_4
Trusted Contributor

Re: Copy ????.ABC ????BCD

SEP

Works better without the -l in the ls command;

Thanks !!

The Perl script is good too ! Thanks.

VEB
Steven E. Protter
Exalted Contributor

Re: Copy ????.ABC ????BCD

Shalom Vernon,

Sorry for the confusion.

thats supposed to be a dash one

-1

What dash one does is create a file list one file per line.

Its possible under certain circumstances at least under hpux to get two files on the same line. dash one prevents that.

I didn't realize with browser fonts and such I needed to clarify its not a dash el.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Vernon Brown_4
Trusted Contributor

Re: Copy ????.ABC ????BCD

Hi SEP;

I tried the script, but would up with the actual ????.EXT question marks in the file name.
code:
unzip ???????k.zip
ls ???????.DRF > list
while read -r filename
do
cp $filename ???????.STK
done < list

Wound up with a file ???????.STK. I'm looking for LAD1117.STK. ( converting horse racing data files from DRF to STK file extension)

Thanks for your help. Still needs work :o)
Vernon Brown_4
Trusted Contributor

Re: Copy ????.ABC ????BCD

Tried a variation:
code:
unzip ???????k.zip
ls ???????.DRF > list
while read -r filename
do
cp $filename $filename.STK
done < list

Wound up with: LAD1117.DRF.STK

Closer but now I need to strip the .DRF; maybe there's a way to strip $filename to the first seven characters; that would do it.
john korterman
Honored Contributor

Re: Copy ????.ABC ????BCD

Hi,

if it is just a mattter of shortening "filename", you could try a small change like this:

.....
while read -r filename
do
#insert cut of filename
if [ "${#filename}" -gt 7 ]
then
filename=$(echo "$filename" | cut -c1-7)
fi
# insert end
cp "$filename" "$filename.STK"
done < list



regards,
John K.
it would be nice if you always got a second chance
Vernon Brown_4
Trusted Contributor

Re: Copy ????.ABC ????BCD

Thanks John; works great !!

Vern