The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Multi File processing orahi001 Shell Programming and Scripting 2 01-10-2008 04:49 PM
Strange difference in file size when copying LARGE file.. 0ktalmagik Filesystems, Disks and Memory 1 06-03-2006 08:34 PM
multi file editing in vi ricl999 Shell Programming and Scripting 0 04-21-2006 08:23 AM
Multi User Multi Task Reza Nazarian UNIX for Dummies Questions & Answers 6 04-13-2006 10:23 AM
multi-file multi-edit kielitaide UNIX for Dummies Questions & Answers 12 06-28-2001 04:12 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-24-2008
jolecanard jolecanard is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 36
Red face 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 (permalink)  
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 (permalink)  
Old 09-25-2008
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
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

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

Last edited by Smiling Dragon; 09-25-2008 at 02:47 AM.. Reason: Just seen era's answered already
  #4 (permalink)  
Old 09-25-2008
jolecanard jolecanard is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 36
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!
  #5 (permalink)  
Old 09-25-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by jolecanard View Post
...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!

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 (permalink)  
Old 10-13-2008
MBN MBN is offline
Registered User
  
 

Join Date: Oct 2008
Location: Hawkes Bay
Posts: 7
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 (permalink)  
Old 10-13-2008
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
Quote:
Originally Posted by MBN View Post
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0