Help with copy command

Hello,

I have a directory in which I have files as follows

CRDT.csv
CRDT.csv.1
CRDT.csv.2
....
CRDT.csv.n

I would like to copy it over to another directory as

crdt_lon.csv
crdt_lon.csv.1
crdt_lon.csv.2
....
crdt_lon.csv.n

I am looking for a one line command but I am unable to come up with it, if I do following it copies it with same name CRDT and I want it to be copied over as crdt_lon

cp CRDT.csv* destdir 

I would really appreciate your help I want these files as crdt_lon* in my destdir. Where destdir can be any directory

Thanks in advance

for files in CRDT*
do
  cp "$files" "${files/CRDT/crdt_lon}"
done

Try this

for file in *
do
   cp $file `echo $file | sed 's/CRDT/crdt_lon/'`
done

@bash-o-logist
The code you gave didn't work for me. I have a solaris box.

regards,
Ahamed

1 Like

Or try..

#!/bin/ksh
for file in CRDT*
do
        cp "$file" "DEST/DIR/crdt_lon.${file#*.}"
done

You must have an old Solaris box.

Hi Ahamed

If I understand correctly you loop through the files and use sed replace to replace CRDT with crdt_lon on each file before it is actually copied correct?

I will give it a try and let you know. Thanks to everyone who replied