How to put text in multiple files using command ECHO?

Viewed 12307

How to put text in multiple files using command echo?

I want to put same text in multiple files, but this command works on only one file:

echo "my text" > myfile.php

But I want a working command line for something like this:

echo "my text" > myfile.php,myfile.txt,myfile,myfile.html

How can I put text in multiple files or custom extension files?

3 Answers

The tee command copies what it reads from standard input to one or more files, and also writes the data to its standard output. So you can use:

echo my text | tee file1 file2 file3 > /dev/null

or maybe:

echo my text | tee file1 file2 > file3

echo your text | tee -a f1 f2 f3

-a for Append to the given FILEs. Do not overwrite. -I for Ignore interrupt signals.

In a parallel universe you might have done:

(echo myfile.php; echo myfile.txt; echo myfile; echo myfile.html; echo /dev/stdout) |\
 parallel 'echo "hello other world" >| {}'

This using GNU parallel (https://www.gnu.org/software/parallel).

Related