Friday, April 26, 2024
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 12039  / 3 Years ago, thu, july 29, 2021, 11:10:52

The command touch {jan,feb,mar}-{Rep.xls,graph.xls} creates files I can't open:



feb-graph.xls jan-Rep.xls feb-Rep.xls mar-graph.xls jan-graph.xls mar-Rep.xls



So I created one template file 1.ods, saved with OO-Calc. Then I tried to copy this file using cp again in the same fashion as cp:



cp 1.ods {jan,feb,mar}{Rep.ods,graph.ods}  


but that doesnt work:




cp: target `margraph.ods' is not a directory




How do I copy a single file to multiple files?


More From » command-line

 Answers
0

Combine cat (retrieves the contents of a file) with tee (writes the content away to the files specified in the arguments):



cat 1.ods | tee {jan,feb,mar}-{Rep,graph}.ods >/dev/null


Alternative using shell redirection:



tee {jan,feb,mar}-{Rep,graph}.ods >/dev/null < 1.ods


In both cases, > /dev/null is a redirection that discards the duplicated contents (tee writes its input to each parameter and standard output).


[#44958] Saturday, July 31, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eeperant

Total Points: 39
Total Questions: 106
Total Answers: 117

Location: Finland
Member since Sat, Dec 5, 2020
3 Years ago
;