Help with copy command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with copy command
# 1  
Old 04-19-2011
Help with copy command

Hello,

I have a directory in which I have files as follows

Code:
CRDT.csv
CRDT.csv.1
CRDT.csv.2
....
CRDT.csv.n

I would like to copy it over to another directory as

Code:
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

Code:
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
# 2  
Old 04-20-2011
Code:
for files in CRDT*
do
  cp "$files" "${files/CRDT/crdt_lon}"
done

# 3  
Old 04-20-2011
Try this

Code:
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
This User Gave Thanks to ahamed101 For This Post:
# 4  
Old 04-20-2011
Or try..
Code:
#!/bin/ksh
for file in CRDT*
do
        cp "$file" "DEST/DIR/crdt_lon.${file#*.}"
done

# 5  
Old 04-20-2011
Quote:
Originally Posted by ahamed101
@bash-o-logist
The code you gave didn't work for me. I have a solaris box.

regards,
Ahamed
You must have an old Solaris box.
# 6  
Old 04-20-2011
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Copy command

Hi , I am trying to take a backup of file before overwriting it with cp command, I am using the command cp -b. -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 a -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 b cp -b a b -rw-rw-r-- 1 autoengine murex 0 Jan 22 07:08 a -rw-rw-r-- 1... (1 Reply)
Discussion started by: Raj999
1 Replies

2. Shell Programming and Scripting

Help with using grep command with copy command

Hi, im taking an entry Unix class, and as part of my lab assignment I have to copy all files in the /home/david/lab3 directory that have the file extension .save to your lab3/temp directory. I'm having trouble getting the grep to do anything worth while I've been trying to do: cp... (6 Replies)
Discussion started by: Critical jeff
6 Replies

3. Shell Programming and Scripting

Help with find and copy command

I entered the following command find . -type f \( -newer startdate -a ! -newer enddate \) -exec cp tmp {} \; I got the following error: cp: 0653-436 tmp is a directory. Specify -r or -R to copy. What's happening here? (2 Replies)
Discussion started by: bbbngowc
2 Replies

4. UNIX for Dummies Questions & Answers

Copy a command string from the command line

How can we copy a command string from a previous command line and paste it into the cursor position on the current command line? I know that ^c will not work as the shell will interpret as an interrupt signal. Thanks, (1 Reply)
Discussion started by: Pouchie1
1 Replies

5. UNIX for Dummies Questions & Answers

help with recursive copy command

Hi Guys, I am experiencing a problem right now while copying a directory as well as its subdirectories to my target directory. I know this is a very simple UNIX command using cp -R source directory target directory. but unfortunatley while doing this an error comes up on the command line saying... (2 Replies)
Discussion started by: Knowledge_Xfer
2 Replies

6. UNIX for Dummies Questions & Answers

Copy file command, why?, how?

scp /path/to/file <username>@<Other Server>:/path/to/newfile If my file is named "Bob" and it is in my user "Accountant" and in a directory named "Invoice_folder"... How would this look in the above? I can't seem to understand the logic of the above scp. MOVING FILE FROM LOCATION #1: /path... (1 Reply)
Discussion started by: woody62
1 Replies

7. Shell Programming and Scripting

Unix copy command

Hi, I have the below command running in unix find /dev/data/ -name "*.*" -exec cp -R {} "/isdev/data//history" \; This command will copy the files from /dev/data/ to /isdev/data//history and will not throw even if there is no files in source. But if i modify the path from... (6 Replies)
Discussion started by: redd
6 Replies

8. Shell Programming and Scripting

Need help in Copy Command

i need to copy some files from a directory and move the copy files to some destination with the extension .dat Can any one help on this (5 Replies)
Discussion started by: ranga27
5 Replies

9. Linux

copy command

sir can any body tell me how i can copy files like copy c:\abc\pqr\mr.txt c:\windows\my documents\this.txt i need command in linux like this really i am a new in linux that is why simple questions alson can any body explain me how i get current directory tree or path in windows... (2 Replies)
Discussion started by: sadiquep
2 Replies

10. Shell Programming and Scripting

copy command

what command would i wrote to copy files from $folder1 to $folder2 ???? (1 Reply)
Discussion started by: perleo
1 Replies
Login or Register to Ask a Question