tags:

views:

311

answers:

5

Hello, example:

I have a file "atest.txt" that have some text..

I want to print this text at files "asdasd.txt asgfaya.txt asdjfusfdgh.txt asyeiuyhavujh.txt"

This files is not exist on my server..

I'm running Debian.. What can i do?

+1  A: 

In bash you can write

#!/bin/bash
$TEXT="hello\nthis is a test\nthank you"
for i in `seq 1 $1`; do echo -e $TEXT >text$i.txt; done

EDIT (in response of question change)

If you can't determine programmatically the names of the target files then you can use this script it:

#!/bin/bash
ORIGIN=$1;
shift
for i in `seq $#`; do cp "$ORIGIN" "$1"; shift; done

you can use it this way:
script_name origin_file dest_file1 second_dest_file 'third file' ...

If you are wondering why there are the double quotes into the cp command, it is for cope with filename containing spaces

Eineki
+1  A: 

From your bash prompt:

for f in test1.txt test2.txt test3.txt; do echo -e "hello\nworld" >> $f; done

If the text lives in atest.txt then do:

for f in test1.txt test2.txt test3.txt; do cat atest.txt >> $f; done
PEZ
+5  A: 

Use the tee(1) command, which duplicates its standard input to standard output and any files specified on the command line. E.g.

printf "Hello\nthis is a test\nthank you\n"
  | tee test1.txt test2.txt $OTHER_FILES >/dev/null

Using your example:

cat atest.txt
  | tee asdasd.txt asgfaya.txt asdjfusfdgh.txt asyeiuyhavujh.txt >/dev/null
Cirno de Bergerac
Hope you don't mind my editing making the answer clearer given the example
Vinko Vrsalovic
UUOC: tee test1.txt test2.txt <atest.txt >/dev/null
PEZ
+2  A: 

Isn't it simply:

cp atest.txt asdasd.txt 
cp atest.txt asgfaya.txt
cp atest.txt asdjfusfdgh.txt
cp atest.txt asyeiuyhavujh.txt

?

Gnudiff
A: 

Can i use

"cp atest.txt asdasd.txt,asgfaya.txt"

??

No. But you can use the for-loop in my answer and do the cp in it.
PEZ
What PEZ said, or you can probably do cat atest.txt | tee asdasd.txt | tee asgfaya.txt
Gnudiff