Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to duplicate the contents of a file. Suppose there is a file named "Hydrogen.element". I want to duplicate the contents of this file with a different name ie.make another file named "Helium.element". I am actually making a periodic table and I want to use the file named "Hydrogen.element" as a template.

share|improve this question

closed as not a real question by bahamat, Renan, Mikel, l0b0, Stéphane Gimenez Sep 17 '12 at 11:07

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Question seems incomplete, just copying the files with different filename ? –  warl0ck Sep 2 '12 at 9:03
1  
yes correct @warl0ck –  Pranit Bauva Sep 2 '12 at 9:20

2 Answers 2

You would like to copy out a list of files from same source:

#!/bin/bash
Elements=('Helium' 'Aluminium' 'Argon') # Items to copy
Source='Hydrogen'  # Copy from this file

for x in "${Elements[@]}"; do 
  cp "$Source" "$x.element"
done

After which I will get:

Aluminium.element Argon.element Helium.element

They all share the same content of Hydrogen

share|improve this answer
    
I am probably doing it wrong but when I run your script, I get only Helium, file. What am I doing wrong? –  jokerdino Sep 2 '12 at 9:49
    
@jokerdino sorry, I made a mistake, now it works ;-P –  warl0ck Sep 2 '12 at 10:05
    
@jokerdino I updated the script and generated result, maybe I'm wrong with your requirements –  warl0ck Sep 2 '12 at 10:27
1  
Never mind me. It actually is working. –  jokerdino Sep 2 '12 at 10:30

Why not use cp command?

for ELEMENT in {1..10}.element; do cp Hydrogen.element element$ELEMENT; done

This command would create 10 files of the name element1.element, element2.element, etc. You can then just rename the files with the relevant element name. If you need to generate more element files, you can change the {1..10} to {1..92} to create 92 files.

(reference)

share|improve this answer
    
i tried it ... its not working! –  Pranit Bauva Sep 2 '12 at 9:16
1  
It should. What happened when you tried? –  jokerdino Sep 2 '12 at 9:20
    
Have you used cd to navigate to the directory? –  njallam Sep 2 '12 at 9:21
    
i tried it with multiple file like cp Hydrogen.element Helium.element Aluminium.element Argon.element Arsenic.element Antimony.element Astatine.element Acitnium.element Americium.element –  Pranit Bauva Sep 2 '12 at 9:21
    
@PranitBauva The given command would work for only element. I'll update my answer in a while with your updated requirement. –  jokerdino Sep 2 '12 at 9:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.