Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 2354  / 1 Year ago, tue, february 7, 2023, 7:21:52

How can I create multiple file from one?
Like, I have 1.json, but want to create 2.json + 3.json + 4.json out of it.


Most obvious way is to just cp 1.json 2.json and so on; but does Linux provide some way to do it in one command?


More From » bash

 Answers
5

You can use a for loop:


for i in {2..4} ; do cp 1.json "$i".json ; done

You can also use tee:


cat 1.json | tee {2,3}.json > 4.json

Instead of using the braces, you can just list the names, too:


for i in 2 3 4 ; do cp 1.json "$i".json ; done
cat 1.json | tee 2.json 3.json > 4.json

[#419] Wednesday, February 8, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tialmes

Total Points: 14
Total Questions: 108
Total Answers: 102

Location: Oman
Member since Thu, Jun 16, 2022
2 Years ago
tialmes questions
;