Bash – How to create multiple files names from list.txt in bash

bashfilestouch

I want to create multiple files at a time using names from a file list.txt, how can I do it?

Sample list.txt:

EOG090W002U
EOG090W00C1
EOG090W00DC
EOG090W00DE
EOG090W00E5
EOG090W00HR
EOG090W00MH
EOG090W00MS
EOG090W00PB
EOG090W00U4
EOG090W00UK
EOG090W00WM
EOG090W00WR

Suppose I have this list.txt containing some id-numbers. Now I want to make separate files using these ids as the name (e.g. EOG090W002U_M0.ctl, EOG090W00C1_M0.ctl, EOG090W00DC_M0.ctl). Also, the contents of the files need to be change accordingly. For example the content of EOG090W002U_M0.ctl, EOG090W00C1_M0.ctl file will be

seqfile = EOG090W002U_p.phy
treefile = Constant.txt
outfile = EOG090W002U_M0_mlc

or

seqfile = EOG090W00C1_p.phy
treefile = Constant.txt
outfile = EOG090W00C1_M0_mlc

where *.phy and Constant.txt will be provided in the same folder.

Best Answer

Simplest:

xargs touch <List.txt

The magic is that xargs takes every line in its stdin and adds it as an argument to the command.

Related Question