Multi-copying a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multi-copying a file
# 1  
Old 09-24-2008
Power Multi-copying a file

Hello there,

I am writting a scrip with in shell (#!/bin/sh) and I need to copy 5 times the same file into different names:
Code:
 
cp xsec.1.11 xsec.1.12
cp xsec.1.11 xsec.1.13
cp xsec.1.11 xsec.1.14
cp xsec.1.11 xsec.1.15
cp xsec.1.11 xsec.1.16

and I have to do that for several file. That takes a lot a place in my script...so I was wondering if there is a way to copy a file in multiple places wit ha single command?

Thanks for your help.
# 2  
Old 09-25-2008
Not directly. Use a loop, perhaps?

Code:
for f in 12 13 14 15 16; do
  cp xsec.1.11 xsec.1.$f
done

What's the use of the multiple copies? Perhaps you could put symbolic links in place once, and be done with it?
# 3  
Old 09-25-2008
This will make five copies of xsec.1.11, five copies of xsec.2.11 and five copies of xsec.3.11. Hopefully this will be enough to get you started?
Code:
for file in xsec.1 xsec.2 xsec.3
do
  for num in 12 13 14 15 16
  do
    cp ${file}.11 ${file}.${num}
  done
done

Sing out if it's still confusing or not what you meant Smilie

edit: oops, that'll teach me to open multipl threads at once then get distracted Smilie

Last edited by Smiling Dragon; 09-25-2008 at 02:47 AM.. Reason: Just seen era's answered already
# 4  
Old 09-25-2008
Thanks for your answers.

Unfortunately I had already though using a loop but I still needed as many lines to do the job...(If I had to make 1000 copies that would be definitely better, but for 5 or 6...).

In fact I wanted to make sure there was not a built-in function capable to do that! Smilie
# 5  
Old 09-25-2008
Quote:
Originally Posted by jolecanard
...Unfortunately I had already though using a loop but I still needed as many lines to do the job...(If I had to make 1000 copies that would be definitely better, but for 5 or 6...).

In fact I wanted to make sure there was not a built-in function capable to do that! Smilie

Code:
while read file
  do
   i=12
   while [ $i -lt 17 ]
    do
      cp -p "$file" /other/dir/"${file%.*}.$i"
      i=$(($i + 1))
    done
  done < files_list

Code:
$ cat files_list
xsec.1.11
xsec.2.11
xsec.3.11
...

Set the counter i (i=12) and the limit (17) to whatever value you desire.
# 6  
Old 10-13-2008
I dunno if what I need is in the sort of same lines as this but I need to copy all *.txt files to a directory but change any reacurring names eg like multi readme.txt would have to rename as to keep all files
# 7  
Old 10-13-2008
Quote:
Originally Posted by MBN
I dunno if what I need is in the sort of same lines as this but I need to copy all *.txt files to a directory but change any reacurring names eg like multi readme.txt would have to rename as to keep all files

It might be better to open a new thread for your problem. Also post a clear sample of your input, expected output, and your efforts so far.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies

2. Programming

Multi head/multi window hello world

I am trying to write a large X app. I have successfully modified my xorg.conf to setup 4 monitors on an NVIDIA Quatro5200. I am trying to modify a simple hello world application to open a window on three of the four monitors. depending on the changes to loop the window creation section and event... (2 Replies)
Discussion started by: advorak
2 Replies

3. Shell Programming and Scripting

How to substract selective values in multi row, multi column file (using awk or sed?)

Hi, I have a problem where I need to make this input: nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b look like this output: nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a -... (4 Replies)
Discussion started by: nricardo
4 Replies

4. Shell Programming and Scripting

Multi-line filtering based on multi-line pattern in a file

I have a file with data records separated by multiple equals signs, as below. ========== RECORD 1 ========== RECORD 2 DATA LINE ========== RECORD 3 ========== RECORD 4 DATA LINE ========== RECORD 5 DATA LINE ========== I need to filter out all data from this file where the... (2 Replies)
Discussion started by: Finja
2 Replies

5. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

6. Shell Programming and Scripting

sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>" FILE1.XML 1. <itemList> 2. <item type="Manufactured"> 3. <resourceCode>431048</resourceCode> 4. ... (0 Replies)
Discussion started by: balrajg
0 Replies

7. Shell Programming and Scripting

Multi File processing

Hello, I have 2 csv files: File1: Name,year,organization Jim,2007,Org1 Bob,1999,Org3 Chris,2001,Org2 File2: DocumentName,DocumentTitle,organization,year Test1,Test1,Org1,2007 Test2,Test2,Org2,2008 Test3,Test3,Org3,2009 Using the ksh, I'm reading by line and grabbing the... (2 Replies)
Discussion started by: orahi001
2 Replies

8. Shell Programming and Scripting

multi file editing in vi

Hi all Some yeras ago (1994) I had a utility that bundled up multiple files into a big file with a seperator lines. Automatically loaded this temp file into vi - which allowed you to edit all the files. then when you :wq or ZZ vi it saved all the files bak to their appropriate file names and got... (0 Replies)
Discussion started by: ricl999
0 Replies

9. UNIX for Dummies Questions & Answers

Multi User Multi Task

Dear Experts Why we always hear that unix operating system is Multi User and Multi task. What does these two means. I have looked at some books and documents but couldn't find aclear explenation. Can we say Windows operating system is also multi user and multi task?? Thanks for your help in... (6 Replies)
Discussion started by: Reza Nazarian
6 Replies

10. UNIX for Dummies Questions & Answers

multi-file multi-edit

Good day! I am trying to learn how to use the "sed" editor, to perform multiple edits on multiple files in multiple directories. I have one script that tries to call up each file and process it according to the edits listed in a second script. I am using a small input text to test these, at... (12 Replies)
Discussion started by: kielitaide
12 Replies
Login or Register to Ask a Question